C++ 检查结构是否为 NULL 或未设置,即使它的 have 运算符相等

标签 c++ struct null

我有一个包含许多成员的结构以及 == 的运算符重载 像这样:

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/

相关文章:

C++:使用传入的字符串参数访问类型中的内容

c++ - 使用 log4cplus 运行代码时出现 bad_alloc 错误

xml - 直接与间接嵌套结构

java - JAXB 中的编码/解码空值

coldfusion - 如何检查 ColdFusion 查询循环中的返回值是否为空值

c++ - vector::clear 的复杂性是否未指定?

c++ - priority_queue 与自定义比较器作为类方法

Swift - 在两个不同的文件中声明结构

c++ - 错误 C2280 : attempting to reference a deleted function while declaring a C++ struct

c++ - 为什么要检查 if (*argv == NULL)?