comp.lang.ada
 help / color / mirror / Atom feed
From: "Mark Lundquist" <up.yerz@nospam.com>
Subject: Re: virtual functions in ada95
Date: Mon, 18 Jun 2001 03:24:09 GMT
Date: 2001-06-18T03:24:09+00:00	[thread overview]
Message-ID: <tveX6.195115$p33.3944309@news1.sttls1.wa.home.com> (raw)
In-Reply-To: 9gg557$8sgga$1@ID-42131.news.dfncis.de


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

OK... don't declare the parameters to the Run subprograms to have classwide
types.  You want them to be primitive to these types.

A classwide parameters says "here is something for me, and also anything
derived from me", i.e. it applies across the derivation class.  (I'm
assuming you realize that Ada uses the word "class" to mean something
completely different than what it means to the rest of the OOPL world...).

Now, there _is_ a connection between classwide types and dispatching...
Specifically, dispatching oocurs only if you have an actual parameter of a
classwide type matched with a formal parameter that is of a specific type.

Also... what's the rationale for using access parameters to Run rather than
'in' or 'in out' parameters?  Just curious...

Hope this keps,
- mark






  parent reply	other threads:[~2001-06-18  3:24 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
2001-06-18  3:24 ` Mark Lundquist [this message]
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