Hi,
I'm trying to compare between two objects of a simple class:
class A
{
int num;
}

void foo()
{
A a,b;
if (a == b)
{
... do domething
}
}

from some reason, it doesnt let me compare the objects. Am I wrong or there
should be a default operator == between the objects?

I get the error:
c:\test\t1.cpp(12) : error C2676: binary '==' : 'A' does not define this
operator or a conversion to a type acceptable to the predefined operator

why???

Help will be appreciated.
Ram.

RE: no default operator == by armancho_x

armancho_x
Tue Apr 19 02:07:02 CDT 2005

Hi Ram

Let you know that no default operator== is defined for a class.
You need define it by yourself. Look at this code:

class A
{
int num;
public:
bool operator == (const A &rhs)
{
return num == rhs.num;
}
};

Now everything is OK!

Re: no default operator == by John

John
Tue Apr 19 02:37:40 CDT 2005

"Ram Baruch" <ram_ba_ruch@newsgroups.nospam> wrote in message
news:uAJeFqKRFHA.356@TK2MSFTNGP14.phx.gbl
> Hi,
> I'm trying to compare between two objects of a simple class:
> class A
> {
> int num;
> }
>
> void foo()
> {
> A a,b;
> if (a == b)
> {
> ... do domething
> }
> }
>
> from some reason, it doesnt let me compare the objects. Am I wrong or
> there should be a default operator == between the objects?

There is a default assignment operator= but no default comparison
operator==.

--
John Carson