comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: virtual functions in ada95
Date: Sat, 16 Jun 2001 19:43:56 GMT
Date: 2001-06-16T19:43:56+00:00	[thread overview]
Message-ID: <0GOW6.96902$%i7.71200801@news1.rdc1.sfba.home.com> (raw)
In-Reply-To: 9gg557$8sgga$1@ID-42131.news.dfncis.de

>How can i use virtual functions in Ada?
  "An Ada dispatching subprogram is analogous to a C++ virtual function."
p 27, Ada as a Second Language, ISBN 0-07-011607-5

> 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;

> procedure Run (Node : access TNTGL_Node_Record'Class);
> procedure Run (Sphere : access TNTGL_Sphere_Record'Class);

  A TNTGL_Sphere_Record, or any descendant of one, is also a descendant of
TNTL_Node_Record.  Which Run would you like to call in that case?
I think you want to drop the 'Class from the Run procedure declarations,
and have Run dispatch based on the run-time type of its paramter.

  procedure Run (Node : access TNTGL_Node_Record);
  procedure Run (Sphere : access TNTGL_Sphere_Record);
anything from a TNTGL_Node_Record up to the parent of a
TNTGL_Sphere_Record would call the first Run, a Sphere or its
descendants would call the second Run.



  parent reply	other threads:[~2001-06-16 19:43 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.
2001-06-16 19:43 ` tmoran [this message]
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