gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-27 23:17:32 26 4
gpt4 key购买 nike

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

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com