Item 26. Multiple Inheritance and the Siamese Twin Problem

I l @ ve RuBoard

Difficulty: 4

Overriding inherited virtual functions is easy, as long as you're not trying to override a virtual function that has the same signature in two base classes. This can happen even when the base classes don't come from different vendors ! What's the best way to separate such "Siamese Twin" functions?

Consider the following two classes:

 class BaseA {   virtual int ReadBuf( const char* );   // ... }; class BaseB {   virtual int ReadBuf( const char* );   // ... }; 

Both BaseA and BaseB are clearly intended to be used as base classes, but they are otherwise unrelated. Their ReadBuf() functions are intended to do different things, and the classes come from different library vendors.

Demonstrate how to write a class Derived , publicly derived from both BaseA and BaseB , which overrides both ReadBuf() s independently to do different things.

I l @ ve RuBoard


More Exceptional C++
More Exceptional C++: 40 New Engineering Puzzles, Programming Problems, and Solutions
ISBN: 020170434X
EAN: 2147483647
Year: 2001
Pages: 118
Authors: Herb Sutter

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net