comp.lang.ada
 help / color / mirror / Atom feed
From: "James S. Rogers" <jimmaureenrogers@worldnet.att.net>
Subject: Re: access on function returning a class wide type
Date: Wed, 20 Nov 2002 00:11:17 GMT
Date: 2002-11-20T00:11:17+00:00	[thread overview]
Message-ID: <FqAC9.22502$hK4.1955169@bgtnsc05-news.ops.worldnet.att.net> (raw)
In-Reply-To: 20021119-223832-295143@foorum.com


"alex" <xela@netcourrier.com> wrote in message
news:20021119-223832-295143@foorum.com...
>
> Is there a "workaround/trick" to implement this kind of think.
>
> package A is
>    type A_T is abstract tagged null record;
>    function Fa return A_T is abstract;
>    type Fa_Ptr is access function return A_T'Class;
> end A;
>
> with A;
> package B is
>   type B_T is new A.A_T with null record ;
>   function Fa return B_T;
> end B;
>
> package body B is
>   function Fa return B_T is
>   begin return (A.A_T with null record);
>   end Fa;
> end B;
>
> with A,B;
> procedure Test is
>    Ptr : A.Fa_Ptr := B.Fa'access; -- error :  LRM:8.6(28)
> begin null;
> end Test;
>
> The compiler is expecting a function returning a A_T'Class, ok I
understand.
> But, B_T is in the A_T'Class!

B_T is in the A_T'Class but a function returning B_T does not return a
class-wide type. You have defined Fa_Ptr to be an access type to a
function returning a class-wide type rooted in type A_T.

Another problem you have is that you are trying to return an instance
of an abstract type. You cannot create an instance of an abstract type.

Jim Rogers





  reply	other threads:[~2002-11-20  0:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-19 21:38 access on function returning a class wide type alex
2002-11-20  0:11 ` James S. Rogers [this message]
2002-11-20  6:39   ` alex
2002-11-20  8:43 ` Jean-Pierre Rosen
2002-11-20 12:39 ` Dmitry A. Kazakov
2002-11-20 15:32 ` Matthew Heaney
replies disabled

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