Message-ID: From: George Kinney To: djgpp AT delorie DOT com Subject: RE: Operator definitio in DJGPP Date: Thu, 14 Sep 2000 10:30:58 -0400 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2448.0) Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C01E58.6B8F2EF8" Reply-To: djgpp AT delorie DOT com This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01C01E58.6B8F2EF8 Content-Type: text/plain; charset="iso-8859-1" >In DJGPP I get the following error message. > --> color& operator+ (const color &,const color &); >this line results in the error message > --> must take either zero or one argument. >I have no problem, if I change the definition to > --> color& operator+ (const color &); > >This is of course not what I what. Does anybody have an idea >where my problem is. FWIW, this is entirely a C++ issue and not a DJGPP one. operator funcs decalred with two args can be friends, but not member functions. so: class foo { int v; public: foo(int); foo& operator +(foo&,foo&); // illegal! foo& operator +(foo&); // legal friend foo& operator +(foo&,foo&); // also legal }; // definition of legal version foo& operator +(foo& a, foo& b) { return foo(a.v + b.v); } you'll have to check with the folks over at news:comp.lang.c++ for the reasons behind this. (I believe it was implemented to allow overloading operators with types in various orders (i.e. operator +(int,float) and operator +(float,int)), but I'm probably wrong) Anyways, good luck. ------_=_NextPart_001_01C01E58.6B8F2EF8 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable RE: Operator definitio in DJGPP

>In DJGPP I get the following error = message.
>    --> color& operator+ = (const color &,const color &);
>this line results in the error message
>    --> must take either zero = or one argument.
>I have no problem, if I change the definition = to
>    --> color& operator+ = (const color &);
>
>This is of course not what I what. Does anybody = have an idea
>where my problem is.

FWIW, this is entirely a C++ issue and not a DJGPP = one.

operator funcs decalred with two args can be friends, = but not member functions.

so:

class foo
{
        int = v;
public:
        foo(int); =

        foo& = operator +(foo&,foo&); // illegal!
        foo& = operator +(foo&);      // legal
        friend = foo& operator +(foo&,foo&); // also legal
};

// definition of legal version
foo& operator +(foo& a, foo& b)
{
        return  foo(a.v + b.v);
}

you'll have to check with the folks over at news:comp.lang.c++ = for the reasons behind
this. (I believe it was implemented to allow = overloading operators with types in various orders (i.e. operator = +(int,float) and operator +(float,int)), but I'm probably = wrong)

Anyways, good luck.

------_=_NextPart_001_01C01E58.6B8F2EF8--