From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,86bb11cd9af49a58 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!newsread.com!news-xfer.newsread.com!news.glorb.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!wn14feed!worldnet.att.net!bgtnsc05-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail From: Dave Thompson Newsgroups: comp.lang.ada Subject: Re: overloading operators with private variables Message-ID: <1ls3u0he60thsfk4mm0vmrtdrku4p18ro4@4ax.com> References: <1104336536.856474.279370@f14g2000cwb.googlegroups.com> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Mon, 10 Jan 2005 03:35:20 GMT NNTP-Posting-Host: 12.75.200.8 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1105328120 12.75.200.8 (Mon, 10 Jan 2005 03:35:20 GMT) NNTP-Posting-Date: Mon, 10 Jan 2005 03:35:20 GMT Organization: AT&T Worldnet Xref: g2news1.google.com comp.lang.ada:7600 Date: 2005-01-10T03:35:20+00:00 List-Id: On 29 Dec 2004 08:08:56 -0800, "R" wrote: > I was trying to overload my test record. For example the > multiplication. > 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