Problem with operator ==

Posted by CPPDev on Stack Overflow See other posts from Stack Overflow or by CPPDev
Published on 2009-12-07T13:44:13Z Indexed on 2010/04/10 18:23 UTC
Read the original article Hit count: 336

Filed under:
|
|

I am facing some problem with use of operator == in the following c++ program.

#include < iostream>
using namespace std;

class A
{
    public:
        A(char *b)
        {
            a = b;
        }
        A(A &c)
        {
            a = c.a;
        }
        bool operator ==(A &other)
        {
            return strcmp(a, other.a);
        }
    private:
        char *a;
};


int main()
{
    A obj("test");
    A obj1("test1");

    if(obj1 == A("test1"))
    {
        cout<<"This is true"<<endl;
    }
}

What's wrong with if(obj1 == A("test1")) line ?? Any help is appreciated.

© Stack Overflow or respective owner

Related posts about c++

Related posts about operators