[omniORB] Ambiguous inheritance error

Randy Shoup rshoup@tumbleweed.com
Tue, 23 Feb 1999 10:16:06 -0800


Rebecca.A.Sanford@notesmta.gd-is.com wrote:
> 
> Hi,
> 
> Sorry for bothering you again, but I'm a little confused by your
> suggestion.  It sounds like you are suggesting an extra layer in
> which the members of C_i would call the appropriate A_i and B_i member
> functions.  That would add a lot of call overhead and I'm unclear how
> constructors and destructors for A_i and B_i would be handled.
> 
> I have used similar IDL and header files with IONA's Orbix without a
> problem.  I was attempting to port the code to omniORB to test for
> interoperability between ORBs.  My actual code contains hundreds of
> functions so perhaps you can understand my lack of eagerness to add
> this extra layer.
> 
> If I'm way off-base, please let me know at your earliest convenience.
> Thanks again for your time.
> 
> Becki Sanford
> General Dynamics Information Systems
> Bloomington, MN
> email: r.sanford@gd-is.com

Ah, the fun of virtual inheritance.  You don't want C_i to inherit
virtually from A_i, B_i.  Something having to do with the "dominance
rule", I suspect, though at this point it's probably just enough to say
that this works:

      class A_i : public virtual Test::_sk_A {
      public:
         void A_foo_1 ();
         void A_foo_2 ();
      };

      class B_i : public virtual Test::_sk_B {
      public:
         void B_foo_1 ();
         void B_foo_2 ();
      };

      class C_i : public virtual Test::_sk_C,
                  public A_i,
                  public B_i {
      public:
         void C_foo_1 ();
         void C_foo_2 ();
      };

Thus you should be able to inherit both interface and implementation. 
This is how we handle implementation classes of base interfaces in our
omniORB application.

> 
> David Riddoch <djr@uk.research.att.com> on 02/23/99 03:54:00
> 
> To:   Rebecca A Sanford/GDIS/GDYN@GDIS
> cc:   omniorb@uk.research.att.com
> Subject:  Re: [omniORB] Ambiguous inheritance error
> 
> Hi Rebecca,
> 
> The reason you are having problems is that you are using C++ inheritance
> to inherit both interface and implementation. The _sk_?? classes provide
> part of the internal implementation of omniORB2, which is then provided
> more than once if you inherit from multiple _sk_?? classes as you have
> done.
> 
> The correct way to inherit the interface is as follows:
> 
>  // File: test_i.h
>  #include "test.hh"
> 
>  class A_i : public Test::_sk_A {
>    ... as you did ...
>  };
> 
>  ... B similarly ...
> 
>  class C_i : public Test::_sk_C {
>    void A_foo_1();
>    void A_foo_2();
>    void B_foo_1();
>    void B_foo_2();
>    void C_foo_1();
>    void C_foo_2();
>  };
> 
> The problem with this though is that we aren't inheriting the
> implementation of A_foo_1() etc. You could achieve this by having separate
> classes which provide the implementation for A and B, and have C_i inherit
> from them. The implementations of A_foo_1() and friends would then just
> delagate to that class.
> 
> Hope this helps,
> David
> 
> PS. Its a good idea to send this sort of question to the mailing list, as
> it would then be seen by a wider audience, and the answer may help others.
> 
> On Mon, 22 Feb 1999 Rebecca.A.Sanford@notesmta.gd-is.com wrote:
> 
> > Perhaps you can help me out with a problem I'm having with multiple
> > inheritance with the omniORB (version 2.70). I'm compiling with MS
> > Visual C++ 5.0 on NT 4.0.  My IDL is structured as follows:
> >
> >
> >      // IDL
> >      module Test {
> >
> >         interface A {
> >            void A_foo_1 ();
> >            void A_foo_2 ();
> >         };
> >
> >         interface B {
> >            void B_foo_1 ();
> >            void B_foo_2 ();
> >         };
> >
> >         interface C : A, B {
> >            void C_foo_1 ();
> >            void C_foo_2 ();
> >         };
> >      };
> >
> >
> > I then created the following header file to define my classes:
> >
> >
> >      // File: test_i.h
> >      #include "test.hh"
> >
> >      class A_i : public virtual Test::_sk_A {
> >      public:
> >         void A_foo_1 ();
> >         void A_foo_2 ();
> >      };
> >
> >      class B_i : public virtual Test::_sk_B {
> >      public:
> >         void B_foo_1 ();
> >         void B_foo_2 ();
> >      };
> >
> >      class C_i : public virtual A_i,
> >                  public virtual B_i,
> >                  public virtual Test::_sk_C {
> >      public:
> >         void C_foo_1 ();
> >         void C_foo_2 ();
> >      };
> >
> >
> > When I attempt to define an object of type "C_i", I get a compiler
> > error stating that 'C_i' has ambiguous inheritances of _sk_C::dispatch
> > and _sk_C::_widenFromTheMostDerivedIntf().
> >
> > Since the IDL compiler inserts those two functions, does this mean that
> > I cannot use multiple inheritances?  Is there a workaround to this
> > problem?  Any information you can toss my way will be greatly appreciated.
> > Thank you in advance for your time and consideration.


-- 

-- Randy
_________________________________________________________________  
Randy Shoup                                     (650)569-3682  
Software Architect                              rshoup@tumbleweed.com  
Tumbleweed Software Corporation