views:

108

answers:

1

Suppose I have the following:

type blah is abstract tagged 
record 
element1 : integer; 
end record;

type blah2 is abstract tagged
record
element2 : integer;
end record;

I'm hoping that it's possible that I can do something like this:

type blah3 is abstract new blah1 and blah 2 with null record;

So in theory I can now access blah3.element1 and blah3.element2

Is this possible? and any hints or tips?

UPDATE:

Would it be possible to references the elements of blah3 (containing blah and blah2) using pointers?

I.E. (this is just a rough idea code is terrible...LOL)

type blah3 is new type with
record
element1 : ptr to blah.element1;
element2 : ptr to blah2.element2;
end record

and are then able to be accessed via blah3.element1 for example?

+4  A: 

Marc C is right (as usual).

Direct Multiple inheritance is very contraversial even in the languages that support it. There are big issues about what the compiler is supposed to do in some edge cases, like when both parent classes define different versions of the same method or member. It was explicitly not allowed in Ada95 when they added inheritance.

So your next question will be "So how do I do what i want to do?"

It depends on what you are trying to achieve by using multiple inheritance. In the worst (most complicated) case you can usually achive the effect you are looking for with "mixin" inheritance. I have done it before, but still I think it is explained best in this AdaIC article: Ada95 and Multiple Inheritance than I could do myself.

Here's a digest:

Ada 95 supports multiple-inheritance module inclusion (via multiple "with"/"use" clauses), multiple-inheritance "is-implemented-using" via private extensions and record composition, and multiple-inheritance mix-ins via the use of generics, formal packages, and access discriminants.

It appears that Ada 2005 has another easier way to do this ("interfaces"), but I haven't had a chance to try that yet. You can read more about it (including why direct MI is still considered bad in Ada) here. I found this example. Again, this will only work if your compiler supports Ada 2005

Interfaces can be composed from other interfaces thus 
type Int2 is interface;
...
type Int3 is interface and Int1;
...
type Int4 is interface and Int1 and Int2;
...
T.E.D.
Unfortunately Ada is 95 I believe, we can't go to 2005....
onaclov2000
I think you have to go the mixin route then. I saw a presentation on it *years* ago and it was pretty slick.
Marc C
Read first linked article then. It was penned by the father of Ada95, and goes into great detail about how to do mixin inheritance with it (with examples).
T.E.D.
I think we're going to try the "updated" method first just to see if it works, if it doesn't then I think mixin will have to be the alternate, Thanks for all the help!
onaclov2000