From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8047848c4805a99e X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Classwide Parameter? Date: Tue, 12 Oct 2004 17:13:29 +0200 Message-ID: References: <1ktf7vgrk5pja.uds5ux4wglit.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de Uvc62NwvTvZ/aV7f6/jJNghcE2Zb08K2ghP6zfGkGqV05zRNc= User-Agent: 40tude_Dialog/2.0.12.1 Xref: g2news1.google.com comp.lang.ada:5098 Date: 2004-10-12T17:13:29+02:00 List-Id: 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