comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: virtual functions in ada95
Date: Sat, 16 Jun 2001 14:08:58 -0500
Date: 2001-06-16T14:08:58-05:00	[thread overview]
Message-ID: <3b2bacbe_2@Newsfeeds.com> (raw)
In-Reply-To: 9gg557$8sgga$1@ID-42131.news.dfncis.de

Declare abstract subprograms in the root type, then when that type is
extended,
the compiler forces you to declare the (concrete) implementation of each
abstract subprogram.

Then, when the abstract subprogram is invoked, the call dispatches to the
implementation according to the derived type with which it was called.

"Thomas Nebel" <thomas_nebel@gmx.de> wrote in message
news:9gg557$8sgga$1@ID-42131.news.dfncis.de...
> Hi
>
> How can i use virtual functions in Ada? I have a superclass and some
classes
> that are derived
> from it:
>
> type TNTGL_Custom_Node_Record is tagged null record;
> type TNTGL_Node_Record is new TNTGL_Custom_Node_Record with private;
> type TNTGL_Visual_Node_Record is new TNTGL_Node_Record with private;
> type TNTGL_Sphere_Record is new TNTGL_Visual_Node_Record with private;
>
> type TNTGL_Node is access all TNTGL_Node_Record'Class;
> type TNTGL_Sphere is access all TNTGL_Sphere_Record'Class;
> ....
> procedure Run (Node : access TNTGL_Node_Record'Class);
> procedure Run (Node : access TNTGL_Group_Node_Record'Class);
> procedure Run (Sphere : access TNTGL_Sphere_Record'Class);
>
> Now i want to "run" the classes from one point transparently :
>
> Node : TNTGL_Node;
> ...
> Node := Scene.First_Node;
> while Node /= null loop
>     Run (Node);
>     Node := Get_Next (Node);
> end loop;
>
> Independent of the real type of the Node variable, the Run function is
> always the Run from
> TNTGL_Node_Record.
>
> How can i manage it, that the Run function for the real Node type is
called
> ?
>
> Thomas
>
>



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----



  reply	other threads:[~2001-06-16 19:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-16 17:31 virtual functions in ada95 Thomas Nebel
2001-06-16 19:08 ` David C. Hoos, Sr. [this message]
2001-06-16 19:43 ` tmoran
2001-06-18  3:24 ` Mark Lundquist
2001-06-18 18:54 ` Thomas Nebel
replies disabled

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