From: "Matthew Heaney" <mheaney@on2.com>
Subject: Re: Abstract methods in ADA95
Date: Thu, 17 Oct 2002 12:18:35 -0400
Date: 2002-10-17T12:18:35-04:00 [thread overview]
Message-ID: <uqtomsakklu238@corp.supernews.com> (raw)
In-Reply-To: 20021017-143635-828420@foorum.com
"Hector Hugo" <hmijares@indra.es> wrote in message
news:20021017-143635-828420@foorum.com...
>
> class Abstract_Class
> {
> public:
> virtual void Abstract_Method () = 0; // C++ abstract method.
>
> ...
> };
This class smells funny, because you didn't make the dtor virtual:
class AC
{
public:
virtual ~AC();
virtual void am() = 0;
};
If you try to delete an object of your original type, your program is
undefined; at a minimum you'll have a memory leak.
Note the the abstract root type must *always* define the dtor --not just
declare it-- even if the dtor is marked as pure virtual.
Also, you should *always* define the dtor as a non-inline function, so that
the vtables have a home.
Ahhh, isn't C++ fun...
> class Son_Class: public Abstract_Class // C++ tagged type extension.
> {
> public:
> void Abstract_Method ();
>
> ...
> };
>
> void main ()
> {
> Abstract_Class* p_abstract = new Son_Class;
>
> p_abstract->Abstract_Method ();
> }
package P is
type T is abstract tagged null record;
procedure Op (O : in out T) is abstract;
end P;
package P.C is
type NT is new T with null record;
procedure Op (O : in out NT);
end P.C;
declare
O : T'Class := NT'(T with null record);
begin
Op (O);
end;
Alternatively, you can allocate off the heap as you did in your C++ example:
declare
type T_Class_Access is access all T'Class;
O : T_CLass_Access := new NT;
begin
Op (O.all);
end;
Or you could rewrite your C++ example to eliminate the heap:
{
Son_Class x;
Abstract_Class* const p = &x;
p->Abstract_Method(); //dispatches
}
Or you could rewrite the C++ example to eliminate the pointer:
{
Son_Class x;
Abstract_Class& y = x;
y.Abstract_Method(); //dispatches
}
Or you could write the example so that the call is statically bound:
{
Son_Class x;
x.Abstract_Method(); //static binding
}
next prev parent reply other threads:[~2002-10-17 16:18 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-17 13:36 Abstract methods in ADA95 Hector Hugo
2002-10-17 14:39 ` Lutz Donnerhacke
2002-10-17 14:50 ` David C. Hoos
2002-10-17 14:57 ` Preben Randhol
2002-10-17 14:56 ` Preben Randhol
2002-10-17 16:18 ` Matthew Heaney [this message]
2002-10-17 19:26 ` Jeffrey Carter
2002-10-17 19:41 ` David C. Hoos
2002-10-17 20:34 ` Georg Bauhaus
2002-10-18 13:56 ` Frank J. Lhota
2002-10-18 0:40 ` Robert A Duff
2002-10-18 21:05 ` Jeffrey Carter
2002-10-18 22:00 ` Robert A Duff
2002-10-21 14:46 ` Wes Groleau
2002-10-18 3:13 ` SteveD
2002-10-18 14:44 ` Robert A Duff
2002-10-18 21:15 ` Dale Stanbrough
2002-10-18 21:08 ` Jeffrey Carter
2002-10-18 21:23 ` David C. Hoos
2002-10-18 21:37 ` Jeffrey Carter
2002-10-18 22:08 ` Robert A Duff
2002-10-21 15:03 ` Peter Amey
2002-10-21 15:04 ` Wes Groleau
2002-10-18 22:10 ` Robert A Duff
2002-10-19 12:40 ` SteveD
2002-10-19 18:40 ` Jeffrey Carter
2002-10-21 15:34 ` Martin Dowie
2002-10-21 19:37 ` Jeffrey Carter
2002-10-22 11:59 ` Georg Bauhaus
2002-10-22 12:24 ` Marin David Condic
2002-10-23 9:29 ` Martin Dowie
2002-10-23 10:36 ` Ed Falis
2002-10-23 10:37 ` Preben Randhol
2002-10-23 12:54 ` John English
2002-10-23 13:48 ` Martin Dowie
[not found] ` <aornkp$mpf$1@bob.news.rcn.net>
2002-10-19 18:54 ` Crapper (was: Re: Abstract methods in ADA95) Jeffrey Carter
2002-10-21 17:57 ` Abstract methods in ADA95 Programmer Dude
2002-10-21 18:58 ` Jim Rogers
2002-10-21 14:49 ` Wes Groleau
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox