+ 2
map operator== is not working for custom data types ?
After creating a map of char(key) and NewClass(value). And creating a copy of the same map, Comparing these two maps dosen't work. Whereas, instead of using NewClass as value if I use an int, It works well. The code is placed below. https://code.sololearn.com/cWu3ZoiW2ZkX/?ref=app
3 Respuestas
+ 2
map can't use your equality operator because it compares const objects.
You equality operator should be defined with const qualifier:
line #8
bool operator==(const NewClass& ref){
should be fixed like this
bool operator==(const NewClass& ref) const{
+ 2
Thanks Shadow and andrly kan. Now it's working fine
+ 1
Try defining the equality operator as a non-member function outside the struct, i.e.
bool operator == ( const NewClass& left, const NewClass& right ) {
if ( left.value == right.value )
return true;
return false;
}