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,92a6dd552088ca30 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!newsfeed2.dallas1.level3.net!news.level3.com!bloom-beacon.mit.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Constructor for a class with a task defined Date: Sat, 03 Sep 2011 18:11:13 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <438414c7-9b01-44ef-8a17-f21d4ef34f58@glegroupsg2000goo.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1315087873 20008 192.74.137.71 (3 Sep 2011 22:11:13 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Sat, 3 Sep 2011 22:11:13 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:eqkISTIWUok5PaZaQXNmlZVqYPk= Xref: g2news2.google.com comp.lang.ada:21813 Date: 2011-09-03T18:11:13-04:00 List-Id: "Rego, P." writes: > function Construct return access Small_Class is > B : access Small_Class := new Small_Class; > begin > return B; > end Construct; > > and got the message "cannot convert local pointer to non-local access type" The type of B is declared inside Construct, whereas the return type is declared outside, so it thinks you might be creating a dangling pointer. Hence the error. I suggest you avoid anonymous access types. They are confusing. And the rules change in Ada 2012. > so why does the (type Small_Class_Acc is access all Small_Class;) code > > function Construct return access Small_Class is > B : Small_Class_Acc := new Small_Class; > begin > return B; > end Construct; > > works? Should not it get me the same msg? No, because now B has a global pointer type. I suggest: function Construct return Small_Class_Acc is B : Small_Class_Acc := new Small_Class; begin return B; end Construct; That way, you know where Small_Class_Acc is declared (probably at library level). - Bob