Mail Archives: djgpp/2000/09/14/11:32:00
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2448.0">
<TITLE>RE: Operator definitio in DJGPP</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=3D2>>In DJGPP I get the following error =
message.</FONT>
<BR><FONT SIZE=3D2>> --> color& operator+ =
(const color &,const color &);</FONT>
<BR><FONT SIZE=3D2>>this line results in the error message</FONT>
<BR><FONT SIZE=3D2>> --> must take either zero =
or one argument.</FONT>
<BR><FONT SIZE=3D2>>I have no problem, if I change the definition =
to</FONT>
<BR><FONT SIZE=3D2>> --> color& operator+ =
(const color &);</FONT>
<BR><FONT SIZE=3D2>></FONT>
<BR><FONT SIZE=3D2>>This is of course not what I what. Does anybody =
have an idea</FONT>
<BR><FONT SIZE=3D2>>where my problem is.</FONT>
</P>
<P><FONT SIZE=3D2>FWIW, this is entirely a C++ issue and not a DJGPP =
one.</FONT>
</P>
<P><FONT SIZE=3D2>operator funcs decalred with two args can be friends, =
but not member functions.</FONT>
</P>
<P><FONT SIZE=3D2>so:</FONT>
</P>
<P><FONT SIZE=3D2>class foo</FONT>
<BR><FONT SIZE=3D2>{</FONT>
<BR> <FONT SIZE=3D2>int =
v;</FONT>
<BR><FONT SIZE=3D2>public:</FONT>
<BR> <FONT SIZE=3D2>foo(int); =
</FONT>
</P>
<P> <FONT SIZE=3D2>foo& =
operator +(foo&,foo&); // illegal!</FONT>
<BR> <FONT SIZE=3D2>foo& =
operator +(foo&); // legal</FONT>
<BR> <FONT SIZE=3D2>friend =
foo& operator +(foo&,foo&); // also legal</FONT>
<BR><FONT SIZE=3D2>};</FONT>
</P>
<P><FONT SIZE=3D2>// definition of legal version</FONT>
<BR><FONT SIZE=3D2>foo& operator +(foo& a, foo& b)</FONT>
<BR><FONT SIZE=3D2>{</FONT>
<BR> <FONT =
SIZE=3D2>return foo(a.v + b.v);</FONT>
<BR><FONT SIZE=3D2>}</FONT>
</P>
<P><FONT SIZE=3D2>you'll have to check with the folks over at <A =
HREF=3D"news:comp.lang.c++" TARGET=3D"_blank">news:comp.lang.c++</A> =
for the reasons behind</FONT>
<BR><FONT SIZE=3D2>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)</FONT></P>
<P><FONT SIZE=3D2>Anyways, good luck.</FONT>
</P>
</BODY>
</HTML>
------_=_NextPart_001_01C01E58.6B8F2EF8--
- Raw text -