comp.lang.ada
 help / color / mirror / Atom feed
* Generic parent accessing his child?
@ 2014-12-06  1:36 hreba
  2014-12-06  7:49 ` Simon Wright
  0 siblings, 1 reply; 3+ messages in thread
From: hreba @ 2014-12-06  1:36 UTC (permalink / 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-12-07  1:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-06  1:36 Generic parent accessing his child? hreba
2014-12-06  7:49 ` Simon Wright
2014-12-07  1:13   ` hreba

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