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

angular - DownloadURL return null in below code -

python 2.7 - Given three nested dictionaries, sort the top two nested dictionaries from a value in the innermost dictionary? -