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


comparing 2 instances of following struct, receive error:

struct mystruct1 {     position(const mystruct2 &_my_struct_2, const int _an_int = -1) :         my_struct_2(_my_struct_2),         an_int(_an_int)     {}      std::string tostring() const;      mystruct2 my_struct_2;     int an_int; }; 

the error is:

error c2678: binary '==' : no operator found takes left-hand operand of type 'myproj::mystruct1' (or there no acceptable conversion)

why?

in c++, structs not have comparison operator generated default. need write own:

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

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -