Re: Multiple inheritance revisited

From: Steven Wurster (stevenwurster_at_lycos.com)
Date: 05/26/04


Date: 26 May 2004 05:25:24 -0700


"Daniel T." <postmaster@eathlink.net> wrote in message news:<postmaster-BE7207.20011625052004@news5.west.earthlink.net>...
> >
> >A problem related to repeated inheritance can still be present even if
> >the base class has no members. Say a base class defines an routine
> >(pure virtual or not), and two sibling descendants redefine that
> >routine. If another class then inherits from both of those siblings
> >(i.e. the dreaded diamond), what happens with the definition of that
> >routine? Even with virtual inheritance in C++, the answer is not
> >automatically defined. The ambiguity must be resolved. Plus if we
> >decide to look at the class higher in the tree, what happens? Eiffel
> >has a resolution for this in the inheritance declaration, but C++ does
> >not.
>
> I don't see that as a problem. The most derived class knows which base
> member-function it wants to use and can declare that. C++'s virtual
> inheritance has no effect if the base classes are forbidden to hold
> member-data.

Yes, the 'leaf' classes can use any of the above member functions, but
that's within their implementation. Either they call one or both, or
write new code. Of course if they decided to call one or both, they
have to use the scope operator to choose which, and if that needs to
be changed later, someone has to go find it and change the proper
code. It's trivial in theory but can easily be more complicated in
practice, especially if there's a lot of ambiguity being resolved this
way.

However, you wondered whether or not forbidding a base class from
having members would eliminate the SI and MI problems, and it won't.
The diamond inheritance that I defined above is still a problem, when
sibling classes both redefine a routine, and their single descendant
has to deal with this. Yes, resolving the ambiguity isn't that big of
a deal, but that's not the only issue here...

What if the sibling descendants decide to covariantly redefine the
return type, which is legal in C++ and some other languages. Even
with virtual inheritance, the bottom of the diamond has resolution
problems with this routine. I know for a fact that the GNU C++
compiler does not support this capability at all, even though it's
legal according to the language definition. We can make all this
trouble happen even when the base class has no members.

Steve



Relevant Pages

  • Re: ambiguous base class (in VC7.1 and Comeau)
    ... I think my solution will be to introduce an additional layer of inheritance ... There's not much you can do with a base class that is ... > non-static members or member functions of the direct base class. ... > can access members of the indirect base, ...
    (microsoft.public.vc.language)
  • Inheritance of static members in the CLR spec vs the C# spec
    ... When i read the CLI spec, 8.10.2 Method inheritance i read the ... "A derived object type inherits all of the instance and virtual methods ... "A class inherits the members of its direct base class. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Binary serialization
    ... Previously I would use a file write routine that worked ... DATA members from the class in question the method of writing each ... the base class where you collect the data in to a byte array which is ... then written to the stream by the base class. ...
    (microsoft.public.dotnet.general)
  • Re: Multiple inheritance revisited
    ... it seems to me that the whole issue with inheritance problems ... >the base class has no members. ... Say a base class defines an routine ...
    (comp.object)
  • Re: Multiple inheritance revisited
    ... it seems to me that the whole issue with inheritance problems ... Say a base class defines an routine ...
    (comp.object)

Loading