comp.lang.ada
 help / color / mirror / Atom feed
From: Dave Thompson <david.thompson1@worldnet.att.net>
Subject: Re: overloading operators with private variables
Date: Mon, 10 Jan 2005 03:35:20 GMT
Date: 2005-01-10T03:35:20+00:00	[thread overview]
Message-ID: <1ls3u0he60thsfk4mm0vmrtdrku4p18ro4@4ax.com> (raw)
In-Reply-To: 1104336536.856474.279370@f14g2000cwb.googlegroups.com

On 29 Dec 2004 08:08:56 -0800, "R" <ruthless@poczta.onet.pl> wrote:

> I was trying to overload my test record. For example the
> multiplication. <snip>
> function "*"(left, right: rec1) return rec1 is
> tmp : Integer;
> ret: rec1;
> begin
> tmp := left.field * right.field;
> Create(ret, tmp);
> return ret; -- I'm not sure if Ada permits returning locally
> -- created objects, C++ don't permit it(well
> references yes)...
> end "*";
> 
C++ (and C) can return by value any fixed type at all _except_ an
array, whether allocated locally or not. (Fixed means in C++
polymorphic = Ada classwide types get sliced.) Returning a _pointer
to_ local space, or (C++ only) a reference to such local space, is an
error, not required to be caught by the compiler although some will
(notably GCC). In Ada the equivalent is diagnosed, because the pointer
type must have a scope larger than the variable, but if you go to the
trouble of overriding it the result is just as wrong.

- David.Thompson1 at worldnet.att.net



      parent reply	other threads:[~2005-01-10  3:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-29 16:08 overloading operators with private variables R
2004-12-29 17:22 ` Vinzent 'Gadget' Hoefler
2005-01-10  3:35 ` Dave Thompson [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox