Re: C++ from Ada, again



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 | //\
\_/ | | \_/`
.



Relevant Pages

  • Re: Why no TV?
    ... >>> No elevators? ... I don't know how they avoid ADA rules. ... And a lot of large cities have parallel YMHA organizations. ...
    (rec.arts.sf.fandom)
  • Re: A couple of questions
    ... shall not mention to avoid a flame war, but suffice to say one language that ... How well does ADA interface with other languages? ... language is going to change/enhance in any way for 2005? ... I guess design by contract could be handled using lots of if then statements ...
    (comp.lang.ada)
  • Re: Why no TV?
    ... KL> No elevators. ... I don't know how they avoid ADA rules. ... cwilbur at chromatico dot net ...
    (rec.arts.sf.fandom)
  • Re: Why no TV?
    ... Marilee J. Layman wrote: ... No elevators. ... I don't know how they avoid ADA rules. ...
    (rec.arts.sf.fandom)