我有一个包含许多成员的结构以及 == 的运算符重载 像这样:
struct Adjustment {
ObjectNumber aD;
Foo afoo;
bool operator == (const Adjustment& aAdjustment) const
{ return (aAdjustment.ID == ID); }
};
在代码中我有:
if(someAdjustment == NULL)
它给了我:
error C2678: binary '==' : no operator found which takes a left-hand operand of type 'Unit::Adjustment' (or there is no acceptable conversion)
所以我的问题是,如何在不更改其代码的情况下检查此结构是否已设置?
最佳答案
您只能将指针与 NULL
进行比较。调整本身永远不会为 NULL。
关于C++ 检查结构是否为 NULL 或未设置,即使它的 have 运算符相等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15502578/