1. Why does it work on simple data types, but not on non-static string members?
Incorrect: Works on anything, but for user defined data types you need to write equality operator. For example if your non static type is char*, you do it like:
class MyClass
{
public:
char* myString;
bool operator == (const MyClass& rhs)
{
if(this == &rhs)
return true;
if(myString == nullptr && rhs.myString == nullptr)
return true;
if(strcmp(myString, rhs.myString) == 0)
return true;
return false;
}
bool operator != (const MyClass& rhs)
{
return !(*this == rhs);
}
};