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 -

Python Tornado package error when running server -

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -