comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Constructor for a class with a task defined
Date: Sat, 03 Sep 2011 18:11:13 -0400
Date: 2011-09-03T18:11:13-04:00	[thread overview]
Message-ID: <wcc1uvxff9a.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 438414c7-9b01-44ef-8a17-f21d4ef34f58@glegroupsg2000goo.googlegroups.com

"Rego, P." <pvrego@gmail.com> 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



  reply	other threads:[~2011-09-03 22:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-01  0:31 Constructor for a class with a task defined Rego, P.
2011-09-01  1:40 ` Adam Beneschan
2011-09-01  4:54   ` Jeffrey Carter
2011-09-01 10:13 ` Simon Wright
2011-09-03 15:18   ` Rego, P.
2011-09-03 22:11     ` Robert A Duff [this message]
2011-09-05  9:37       ` Georg Bauhaus
2011-09-08 10:22       ` Rego, P.
replies disabled

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