comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <no.spam@no.spam.com>
Subject: Re: Basic Explaination of OO in Ada
Date: Wed, 20 Sep 2006 09:16:22 +0200
Date: 2006-09-20T09:16:22+02:00	[thread overview]
Message-ID: <eeqps7$9qs$1@sunnews.cern.ch> (raw)
In-Reply-To: <1158679879.965952.156540@m73g2000cwd.googlegroups.com>

Ludovic Brenta wrote:


> Here's another interesting tip for C++ programmers. In C++, once you
> declare a member function to be "virtual", all calls to that member
> function dispatch  dynamically, across the entire program.

Except when you ask it otherwise by qualifying the function name at the 
call site, see below.

> Conversely,
> if a member function lacks the "virtual" keyword, calls to it are
> always static. The only way you can determine whether calls dispatch
> statically or dynamically is by looking at the declaration of the
> member function. Things can become quite nasty if a class overrides an
> inherited, non-virtual member function, and makes it virtual.

Yes, it becomes nasty. It's a classical no-no for C++ programmers.

> I'm not
> even sure what the language rules are in this case.

The static type used to call determines whether it dispatches or not, 
because it's the static type (of the pointer or reference) that allows 
to check whether the function is virtual.

> In contrast, in Ada, you do not declare primitive operations as
> "virtual", or "dynamic" or whatever. Instead, you choose *at the point
> of call* whether or not the call dispatches. Consider:
> 
> with Pak; use Pak;
> procedure Test (Object : in out T'Class) is
> begin
>    P (Object); -- dynamic dispatch
>    P (T (Object)); -- view conversion to a specific type => static
> dispatch
> end Test;

Similar for C++:

p->fun(); // dynamic dispatch if in *p fun is virtual
p->BaseClass::fun(); // no dynamic dispatch


-- 
Maciej Sobczak : http://www.msobczak.com/
Programming    : http://www.msobczak.com/prog/



  parent reply	other threads:[~2006-09-20  7:16 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-18 15:24 Basic Explaination of OO in Ada richard.charts
2006-09-18 16:31 ` Georg Bauhaus
2006-09-18 16:43 ` Georg Bauhaus
     [not found] ` <j%zPg.13190$bM.10526@newsread4.news.pas.earthlink.net>
2006-09-18 17:13   ` Javier Miranda
2006-09-18 17:51 ` Robert A Duff
2006-09-18 18:32 ` Gautier
2006-09-18 19:55   ` richard.charts
2006-09-19  3:29     ` Lucretia
2006-09-19  8:49     ` gautier_niouzes
2006-11-20  6:13     ` adaworks
2006-11-24 14:48       ` Marco
2006-11-24 15:15         ` Javier Miranda
2006-09-18 19:37 ` Lucretia
2006-09-18 20:25 ` Jeffrey R. Carter
2006-09-19  3:32   ` Lucretia
2006-09-19 13:56     ` richard.charts
2006-09-19 14:10       ` Lucretia
2006-09-19 14:23         ` richard.charts
2006-09-19 15:45           ` Dmitry A. Kazakov
2006-09-19 15:31       ` Ludovic Brenta
2006-09-19 15:56         ` Alex R. Mosteo
2006-09-19 16:06           ` Ludovic Brenta
2006-09-19 16:14             ` Alex R. Mosteo
2006-09-20  7:16         ` Maciej Sobczak [this message]
2006-09-19 20:45       ` Jeffrey R. Carter
2006-09-19 21:15         ` Hyman Rosen
2006-09-20  7:27           ` Dmitry A. Kazakov
2006-09-19  6:00 ` Martin Krischik
2006-09-19 20:33   ` Jeffrey R. Carter
2006-09-20  6:41     ` Martin Krischik
2006-09-21  1:37       ` Randy Brukardt
replies disabled

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