小编Gro*_*tel的帖子

No match for operator != (operands types are pointer and object)

I'm overloading both == and != operators and want the latter to refer to the former in order to not repeat any code at all. This is what I have written:

bool Date :: operator == (const Date & other) const {
    bool are_equal = Year() == other.Year();

    for (int i=0; i<other.NumEvents() && are_equal; i++)
        are_equal = this[i] == other[i];

    return are_equal;
}

bool Date :: operator != (const Date & other) const {
    return !(this == other);
}
Run Code Online (Sandbox Code Playgroud)

The …

c++ pointers operator-overloading this c++11

2
推荐指数
1
解决办法
51
查看次数

标签 统计

c++ ×1

c++11 ×1

operator-overloading ×1

pointers ×1

this ×1