用VS2008,为什么会这样(2010不允许用)。
void assert(int exp, int actual) {if (exp!=actual) printf("assert failed\n");}
void assert(unsigned int exp, unsigned int actual) {if (exp!=actual) printf("assert failed\n");}
但这是模棱两可的。
void assert(__int64 exp, __int64 actual) {if (exp!=actual) printf("assert failed\n");}
void assert(unsigned __int64 exp, unsigned __int64 actual) {if (exp!=actual) printf("assert failed\n");}
示例错误文本
d:\my documents\visual studio 2008\projects\classtest\classtest\classtest.cpp(31) : error C2668: 'assert' : ambiguous call to overloaded function
d:\my documents\visual studio 2008\projects\classtest\classtest\classtest.cpp(12): could be 'void assert(unsigned __int64,unsigned __int64)'
d:\my documents\visual studio 2008\projects\classtest\classtest\classtest.cpp(10): or 'void assert(__int64,__int64)'
while trying to match the argument list '(int, int)'
它只会在“无符号”重载方面变得模棱两可。拥有和“int”版本和“__int64”版本并不模棱两可。