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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,9fd97969641aa8c6 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!proxad.net!newsfeed.stueberl.de!newsfeed01.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail From: Martin Krischik Newsgroups: comp.lang.ada Subject: Re: how can i allocate an objekt with initialization??? Date: Mon, 06 Dec 2004 14:34:13 +0100 Organization: None Message-ID: <1654535.Ng2VDZFboh@linux1.krischik.com> References: <3459883.9H2ke8dEzz@linux1.krischik.com> <41b44663$0$9298$ba620e4c@news.skynet.be> Reply-To: martin@krischik.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.t-online.com 1102345504 04 5377 lnyMXLRl+gBsSBSB 041206 15:05:04 X-Complaints-To: usenet-abuse@t-online.de X-ID: bo3RJuZOoeTQoLts-PKbGXgcDDwOua-E7bOt54OCv9sRS1DrsHcS8k User-Agent: KNode/0.8.0 Xref: g2news1.google.com comp.lang.ada:6804 Date: 2004-12-06T14:34:13+01:00 List-Id: Adrien Plisson wrote: > Ole-Hjalmar Kristensen wrote: > the corresponding C++ example should have been: > > int main(int argc, char *argv[]) > { > a &my_object = b(1); I have seen this before and I am wondering if it is actualy valid. Because: where is the result of the b(1) constructor call been stored? a& can only hold a reference to retun value. Is this not a variation on the classic mistake. int& f () { auto int retval = 5; // do something return retval; } and that would mean that the livetime of the constructor call result is undefined. > my_object.f(); > > return 0; > } > Martin PS: The above problem case can actually happen to anyone - when hidden by implicid type convertion extern int &f(); -- returns valid reference unsigend& g () { return f(); -- just delegate. } IBM C++ will convert int& to unsigned& - works fine MS C++ will convert int& to int to unsigned to unsigned& - :-(( -- mailto://krischik@users.sourceforge.net http://www.ada.krischik.com