首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

关于effective c++ 条款 25的一个有关问题 来

2012-03-09 
关于effective c++条款 25的一个问题 高手进来啊以下是effectivec++里面的一段条款25voidf(intx)voidf(st

关于effective c++ 条款 25的一个问题 高手进来啊
以下是effective   c++里面的一段   条款25

void   f(int   x);
void   f(string   *ps);

void   *   const   null   =   0;//可能的null定义

f(0);//调用f(int)
f(static_cast(null));//调用f(string*)
f(static_cast(0));                   //调用f(string*)


其中的
f(static_cast(null));
f(static_cast(0));

小弟翻遍了书和质料也没找到有这种用法啊   而且在vc下也不能编译通过
恳请各位大哥指点迷津啊

[解决办法]
你看书不认真,或者,你用的effectivce c++电子版是错版
原书写的是:
f(static_cast <string*> (NULL)); // 调用f(string*)
f(static_cast <string*> (0)); // 调用f(string*)

[解决办法]
up

void * const NULL = 0; // potential NULL definition
f(0); // still calls f(int)
f(static_cast <string*> (NULL)); // calls f(string*)
f(static_cast <string*> (0)); // calls f(string*)


f(0); // calls f(int)
f(NULL); // error! — type mis-match
f(static_cast <string*> (NULL)); // okay, calls f(string*)

[解决办法]
特地去看了下我收藏的effective c++果真有一个版本的中文版是楼主这样的错误,估计是笔误,2楼正确

热点排行