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,e859f774bbb3dfb3 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!p25g2000hsf.googlegroups.com!not-for-mail From: christoph.grein@eurocopter.com Newsgroups: comp.lang.ada Subject: Re: another way to shoot yourself in the foot? Date: Fri, 20 Jun 2008 03:05:29 -0700 (PDT) Organization: http://groups.google.com Message-ID: <54435596-5e7f-4686-a2b7-1e22d7c4b186@p25g2000hsf.googlegroups.com> References: <54157920-377a-441b-9b0b-f0c4f9ddffec@f36g2000hsa.googlegroups.com> NNTP-Posting-Host: 80.156.44.178 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1213956329 14904 127.0.0.1 (20 Jun 2008 10:05:29 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 20 Jun 2008 10:05:29 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: p25g2000hsf.googlegroups.com; posting-host=80.156.44.178; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1),gzip(gfe),gzip(gfe) X-HTTP-Via: 1.1 webwasher (Webwasher 6.7.0.3295) Xref: g2news1.google.com comp.lang.ada:776 Date: 2008-06-20T03:05:29-07:00 List-Id: > --- Factory ads --- > with Named; > with Some; > > package Factory is > =A0 =A0function Create(class: String; name: String) return > Named.Object'Class; > end Factory; > > --- Factory.adb --- > > with Ada.Strings.Fixed; use Ada.Strings.Fixed; > with Some; > > package body Factory is > =A0 =A0--- this one is ugly, but in sake of simplicity ... > =A0 =A0function Create(class: String; name: String) return > Named.Object'Class is > =A0 =A0begin > =A0 =A0 =A0 if Index(class, "Some") /=3D 0 then > =A0 =A0 =A0 =A0 =A0return Some.Create(name); > =A0 =A0 =A0 end if; > =A0 =A0 =A0 raise Program_Error with "Unknown class " & class; > =A0 =A0end; > end Factory; Since Some.Object is limited, Factory must construct in place. The normal return statement produces a copy (I guess there should be a warning here - no compiler bug, since the RM has nothing to say about warnings). So use the extended return statement as in Some.Create. (This is just a guess, dunno if it helps.)