comp.lang.ada
 help / color / mirror / Atom feed
From: hreba <hreba@terra.com.br>
Subject: Generic parent accessing his child?
Date: Fri, 05 Dec 2014 23:36:35 -0200
Date: 2014-12-05T23:36:35-02:00	[thread overview]
Message-ID: <cef4t5Ff8n5U1@mid.individual.net> (raw)

Without generics I had no problem letting a parent access his child, a 
"with" was enough. With generics I have the following problem:

-------------------------------------------------------

generic		-- a package used as generics parameter
package T is
    type	Ttype is private;
    procedure Init (t: in out Ttype);
private
    type Ttype is new Integer;
end T;

package body T is
    procedure Init (t: in out Ttype) is
    begin
       t:= 0;
    end Init;
end T;

--------------------------------------------------------

with T;		-- the parent
generic
    with package U is new T(<>);
package P is
    type AD is abstract tagged null record;
    type A is access all AD'Class;
    function NewA return A;
end P;

with P.Q;
package body P is
    function NewA return A is
    begin
       return A(P.Q.NewB);	--  <-- ERROR
    end NewA;
end P;
-------------------------------------------------------

generic		-- the child
package P.Q is
    type BD is new AD with
       record
          i:	U.Ttype;
       end record;
    type B is access all BD;
    function NewB return B;
end P.Q;

package body P.Q is
    function NewB return B is
       b0: B;
    begin
       b0:= new BD;
       U.Init(b0.i);
       return b0;
    end NewB;
end P.Q;

-----------------------------------------------------

The error message refers to the line marked above and reads:

Invalid prefix in selected component "Q".

What would be the correct way?

-- 
Frank Hrebabetzky		+55 / 48 / 3235 1106
Florianopolis, Brazil


             reply	other threads:[~2014-12-06  1:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-06  1:36 hreba [this message]
2014-12-06  7:49 ` Generic parent accessing his child? Simon Wright
2014-12-07  1:13   ` hreba
replies disabled

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