No == operator found while comparing structs in C++

前端 未结 8 952
说谎
说谎 2020-12-02 09:21

Comparing two instances of the following struct, I receive an error:

struct MyStruct1 {
    MyStruct1(const MyStruct2 &_my_struct_2, const int _an_int =          


        
8条回答
  •  失恋的感觉
    2020-12-02 10:06

    In C++, structs do not have a comparison operator generated by default. You need to write your own:

    bool operator==(const MyStruct1& lhs, const MyStruct1& rhs)
    {
        return /* your comparison code goes here */
    }
    

提交回复
热议问题