nullptr和NULL区别
nullptr和NULL的区别:
- NULL 宏 替换的是整型的0; nullptr c++关键字。
- 含义不同:NULL代表整形数字,nullptr代表空指针。
void show(char *p)
{cout<<"show(char *p)"<<endl;
}void show(int a)
{cout<<"show(int a)"<<endl;
}void show(int *a)
{cout<<"show(int *a)"<<endl;
}
show(NULL); // NULL 0 调用void show(int a)函数;
show((char *)nullptr); //调用void show(char *p)函数
show((int*)nullptr); //调用void show(int *a)
引入nullptr为了解决调用不明确的问题,nullptr代表各种类型的空指针,可以通过强转来区分
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
