Re: C++ from Ada, again
- From: Yves Bailly <kafka.fr@xxxxxxxxxxx>
- Date: Sat, 20 May 2006 17:12:42 +0200
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 | //\
\_/ | | \_/`
.
- References:
- C++ from Ada, again
- From: Yves Bailly
- C++ from Ada, again
- Prev by Date: Re: Dot notation in Ada 2005
- Next by Date: Exceptions and Streams
- Previous by thread: Re: C++ from Ada, again
- Next by thread: Dot notation in Ada 2005
- Index(es):
Relevant Pages
|
|