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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8a602a7f65bebaea X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-10-17 09:19:45 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed-west.nntpserver.com!hub1.meganetnews.com!nntpserver.com!telocity-west!TELOCITY!sn-xit-03!sn-xit-01!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Matthew Heaney" Newsgroups: comp.lang.ada Subject: Re: Abstract methods in ADA95 Date: Thu, 17 Oct 2002 12:18:35 -0400 Organization: Posted via Supernews, http://www.supernews.com Message-ID: References: <20021017-143635-828420@foorum.com> X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Complaints-To: abuse@supernews.com Xref: archiver1.google.com comp.lang.ada:29876 Date: 2002-10-17T12:18:35-04:00 List-Id: "Hector Hugo" 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 }