Pop quiz:
When run result_1 is true, but the result_2 is false. Can anyone explain why this is ?
Regards,
Rich.
Code:
class MyStr
{
public:
MyStr(const char* newValue):s(newValue)
{
}
operator const char*()
{
return s.c_str();
}
bool operator == (MyStr& rhs)
{
return rhs.s == s;
}
private:
std::string s;
};
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
MyStr a("hello"), b("hello");
BOOL result_1 = (a == b);
BOOL result_2 = (MyStr("hello") == MyStr("hello"));
return 0;
};
When run result_1 is true, but the result_2 is false. Can anyone explain why this is ?
Regards,
Rich.