有一个类有两个相似的构造函数......
class CX
{
public:
CX(HEADER header,
__int64 i64Id);
CX(HEADER header,
const char* pszName);
// other methods...
};
我想用空指针调用第二个构造函数。
CX *data1 = new CX(&header, NULL);
//it is ambiguous call to overloaded function
CX *data2 = new CX(&header, (const char*)NULL);
// is correct, but against our coding standards...
CX *data3 = new CX(&header, static_cast<const char*>(NULL));
// is correct, but agains our coding standards...
const char* pszName = NULL;
CX *data4 = new CX(&header, pszName);
// this is correct but waste of stack.
有没有更好的方法来选择构造函数?
(在这种情况下,nullptr 将是解决方案,但这是不可能的,因为它应该可以在 VC6 中编译)