NULL 与 nullptr  
   
所属分类 c
浏览量 1111
NULL 歧义 二义性 syntax ambiguous
void*指针值 0
整数常量 0
#define NULL (void*)0  
// lmcons.h 
#ifndef NULL  
#ifdef __cplusplus  
#define NULL    0  
#else  
#define NULL    ((void *)0)  
#endif  
#endif  
nullptr在C++11中就是代表空指针,不能转换成数字
#include "iostream"
#include "string"
using namespace std;
void func(int* num){
    cout << "func(int* num)" << endl;
}
void func(int num){
    cout << "func(int num)" << endl;
}
int main(){
  cout << "NULL=" << NULL << endl;
  cout << "nullptr=" << nullptr << endl;
  //  error: call to 'func' is ambiguous  
  // func(NULL);
  func(0);
  func(nullptr);
 
  return 0;
}
NULL=0
nullptr=nullptr
func(int num)
func(int* num)
 上一篇  
   
 下一篇  
 c++11 STL 例子 
 c++模板和java泛型 
 c++11 线程实例 
 c++ 变量名 冲突 
 c++ rapidjson 使用 
 大端和小端模式