delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/09/14/11:32:00

Message-ID: <DB85AFBE7C0DD311BF260004ACB80BFC09D682@nex_server.nextransport.com>
From: George Kinney <GKinney AT nextransport DOT com>
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)
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

<!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>&gt;In DJGPP I get the following error =
message.</FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp;&nbsp;&nbsp; --&gt; color&amp; operator+ =
(const color &amp;,const color &amp;);</FONT>
<BR><FONT SIZE=3D2>&gt;this line results in the error message</FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp;&nbsp;&nbsp; --&gt; must take either zero =
or one argument.</FONT>
<BR><FONT SIZE=3D2>&gt;I have no problem, if I change the definition =
to</FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp;&nbsp;&nbsp; --&gt; color&amp; operator+ =
(const color &amp;);</FONT>
<BR><FONT SIZE=3D2>&gt;</FONT>
<BR><FONT SIZE=3D2>&gt;This is of course not what I what. Does anybody =
have an idea</FONT>
<BR><FONT SIZE=3D2>&gt;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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2>int =
v;</FONT>
<BR><FONT SIZE=3D2>public:</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2>foo(int); =
</FONT>
</P>

<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2>foo&amp; =
operator +(foo&amp;,foo&amp;); // illegal!</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2>foo&amp; =
operator +(foo&amp;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // legal</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2>friend =
foo&amp; operator +(foo&amp;,foo&amp;); // also legal</FONT>
<BR><FONT SIZE=3D2>};</FONT>
</P>

<P><FONT SIZE=3D2>// definition of legal version</FONT>
<BR><FONT SIZE=3D2>foo&amp; operator +(foo&amp; a, foo&amp; b)</FONT>
<BR><FONT SIZE=3D2>{</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT =
SIZE=3D2>return&nbsp; 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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019