【发布时间】:2011-10-12 22:40:23
【问题描述】:
在 GCC 更高版本中。当一个有多个使用引用或指针的构造函数时,一个(如果可以的话)如何消除“0”或“NULL”的歧义?
即:
class XXX
{
public:
XXX(const XXX &tocopy);
XXX(const char *fromAString);
XXX(const AnotherThing *otherThing);
operator=(const XXX &tocopy);
operator=(const char *fromAString);
operator=(const AnotherThing *otherThing);
};
// nice not to have to cast when setting to NULL for
// things like smart pointers and strings. Or items that can be initialized from
// several types of objects and setting to null means "clear"
XXX anXXX = NULL;
anXXX = 0;
// In MSC one can have an
// XXX(const int &nullItem) { DEBUG_ASSERT(!nullItem); setnull(); }
// and the overloads would be disambiguated. GCC will cause a const int to conflict
// with pointer types.
【问题讨论】:
标签: c++ gcc compilation