comp.lang.ada
 help / color / mirror / Atom feed
From: "VC" <vchan@drs.ca>
Subject: accessing subprogram & inheritance problem
Date: Mon, 05 Feb 2001 23:12:22 GMT
Date: 2001-02-05T23:12:22+00:00	[thread overview]
Message-ID: <qrGf6.525$f5.98165@news> (raw)

How do I make the following program to compile and work?
I would like to have a subprogram pointer in the root class which
can be used to point to the subprograms in the child class as well.
Is it possible at all with Ada95?

Vicky
---------------------------------------------------------------
with Ada.Text_Io;
use Ada.Text_Io;

procedure Mytest is

   type Root_T;

   type Action_Ptr_T is access
     procedure(Object : in Root_T);

   type Root_T is tagged
      record
         Action_Ptr : Action_Ptr_T;
      end record;

   procedure Root_Action (Object : in Root_T) is
   begin
      Put_Line("Root Action");
   end;

   type Child_T is new Root_T with null record;

   procedure Child_Action (Object : in Child_T) is
    begin
      Put_Line("Child Action");
   end;

   My_Object : Root_T;
   My_Child : Child_T;

begin

   My_Object.Action_Ptr := Root_Action'Access;
   My_Object.Action_Ptr(My_Object);  -- this printed out "Root Action"

   My_Child.Action_Ptr := Child_Action'Access;
   My_Child.Action_Ptr(My_Child);  -- would like it to print "Child Action"

end Mytest;






             reply	other threads:[~2001-02-05 23:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-02-05 23:12 VC [this message]
2001-02-06  4:43 ` accessing subprogram & inheritance problem tmoran
2001-02-06  7:59   ` Sven Nilsson
2001-02-08  1:53 ` Robert Brantley
2001-02-08  4:36   ` tmoran
2001-02-08 18:48     ` Robert Brantley
replies disabled

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