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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,dc678c047f29ac37 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!130.59.10.21.MISMATCH!kanaga.switch.ch!switch.ch!news.in2p3.fr!in2p3.fr!proxad.net!cleanfeed1-a.proxad.net!nnrp2-2.free.fr!not-for-mail Message-ID: <446f31eb$0$6996$626a54ce@news.free.fr> From: Yves Bailly Subject: Re: C++ from Ada, again Newsgroups: comp.lang.ada Date: Sat, 20 May 2006 17:12:42 +0200 References: <446cee4e$0$5159$626a54ce@news.free.fr> User-Agent: KNode/0.10.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit Organization: Guest of ProXad - France NNTP-Posting-Date: 20 May 2006 17:12:43 MEST NNTP-Posting-Host: 81.56.171.53 X-Trace: 1148137963 nnrp2-2.free.fr 6996 81.56.171.53:54567 X-Complaints-To: abuse@proxad.net Xref: g2news2.google.com comp.lang.ada:4314 Date: 2006-05-20T17:12:43+02:00 List-Id: Hello all, I've refined my last try to call C++ from Ada. Grab it there: http://kafka-fr.hd.free.fr/~yves/cpp_from_ada.tar.bz2 Now memory is dynamically allocated, which I wanted to avoid. But I didn't find another way to keep the inheritance semantic. So basically, given a C++ class "Base" and a derived class "Derived": class Base { ... }; class Derived: public Base { ... }; ...now you keep this model into Ada: type Base is tagged ... -- details omitted here type Derived is new Base with ... -- details omitted here So the C++ hierarchy is reflected in Ada. If you create new derived type into Ada, overriding virtual methods, the dispatching occures as you would expect. More precisely, the C++ class contains: class Base { public: void method() { // calls the virtual method virtual_method(); } virtual void virtual_method() { /* ...something...*/ } }; (actually the code contains many std::cout to keep track of the flow) This is translated in Ada by: type Base is tagged ... -- details omitted here not overriding procedure Method(b: in Base'Class); not overriding procedure Virtual_Method(b: in Base); Now suppose you derive from Base: type Sub is new Base with null record; overriding procedure Virtual_Method(s: in Sub); Then create an instance: s: Sub; ...when you invoke Method(s), the Virtual_Method() called is the overriden one. I tried to avoid as much as possible any compiler- or platform-specific features. However I don't have access to anything else than Gnat and a Linux/i386 platform. Thanks to point me anything not portable. Any comments welcome ! I'm not that experienced in those things... Best regards, -- (o< | Yves Bailly : http://kafka-fr.net | -o) //\ | Linux Dijon : http://www.coagul.org | //\ \_/ | | \_/`