comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Classwide Parameter?
Date: Tue, 12 Oct 2004 17:13:29 +0200
Date: 2004-10-12T17:13:29+02:00	[thread overview]
Message-ID: <r1dw4xpckuk1$.1x79i33e4ubz7.dlg@40tude.net> (raw)
In-Reply-To: ckg3p6$abj$01$1@news.t-online.com

On Tue, 12 Oct 2004 10:14:57 +0200, matthias_k wrote:

>> Ah! I -totally- misunderstood the meaning of 'class. I thought it makes 
>> a method 'virtual' in C++ speaking, therefore allow subclasses to 
>> override it and being called dynamically.
>> 
>> Thanks for clearing up.
> 
> If you ask why the hell I thought that:
> 
> [quoted from "Big Online Book of Linux Ada Programming" 
> (http://www.vaxxine.com/pegasoft/homes/11.html#11.3)]
> 
> Ada 	                          Description 	        C Equivalent
> [...]
> 'class 	                          Class-wide type 	virtual <-- !
> [...]

Well, it is not that wrong as it appears. Keep in mind:

       subroutines
      /          \
primitive       non-primitive
(override)       (overload)
[can dispatch]    /      \
             specific   class-wide

    objects
   /       \
specific   class-wide [can dispatch]

The page you refer tells about *objects*. T'Class object in Ada has the
functionality of the first (prefix) actual parameter of a virtual function
in C++ (what "this" points to). Both dispatch:
---------------------------
class X
{
public :
   virtual void Foo (); // "Primitive in Ada"
};
X& Object = ...;

X.Foo (); // This dispatches
---------------------------
type X is tagged ...
procedure Foo (Object : X); -- "Virtual in C++"

   Object : X'Class := ...; -- Note X'Class!!
begin
   Foo (Object); -- This dispatches
---------------------------
In this sense X'Class is an "equivalent" of virtual.

But. C++ pretends X and X'Class be same types, so it is forced to dispatch
and re-dispatch everywhere and every time. In this sense any C++ function
is a kind of "class-wide" (except for ctor/dtor) in any of its X& or X*
parameters when they are used within in the prefix form:

friend void Baz (X& Object)
{
   Object.Foo (); // This dispatches, Baz is "class-wide"?
   Baz (Object);  // But this does not, Baz is not "class-wide"?
}

Anyway, the equivalence chart should include all combinations of types of
objects and subroutines + parameter positions because of that nasty prefix
notation in C++.

Roughly, when in Ada a class-wide object meets a primitive operation it is
an equivalent of C++'s call to a virtual function through its first
parameter. Ada's class-wide subroutines are equivalent to C++'s friend
functions, non-virtual functions, functions with explicit parameters etc,
when the parameter is a reference or a pointer to some C++ class. Ada's
specific subroutines are equivalent to C++ functions having a parameter,
which type/class does not have virtual functions.

Honestly it is wasting time to search for meaningful analogies! (:-))
Fortunately in Ada it is quite simple. The mantra is:

It dispatches IFF a class-wide object meets a specific parameter of a
primitive operation.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2004-10-12 15:13 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-11 16:01 Classwide Parameter? matthias_k
2004-10-11 16:53 ` Matthew Heaney
2004-10-11 17:08   ` matthias_k
2004-10-11 19:16     ` Simon Wright
2004-10-11 22:53     ` Brian May
2004-10-12  2:29     ` Matthew Heaney
2004-10-12  8:01       ` matthias_k
2004-10-12  8:53         ` Martin Krischik
2004-10-12 13:10         ` Matthew Heaney
2004-10-12  7:59     ` Dmitry A. Kazakov
     [not found]       ` <ckg3h6$qau$03$1@news.t-online.com>
2004-10-12  8:14         ` matthias_k
2004-10-12 15:13           ` Dmitry A. Kazakov [this message]
2004-10-12  8:10     ` Martin Krischik
replies disabled

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