Multiple Inheritance
On the Symbian platform, the use of multiple interface class (M class) inheritance is the only form of multiple inheritance that is encouraged.
The following example illustrates a class which inherits from CBase and two mixin interfaces, MRadio and MClock. In this case, MClock is
18For a thorough discussion of this topic applied to the Singleton pattern, please refer to the April 2008 Code Clinic article at developer.symbian.org/wiki/index.php/ WSD_and_the_Singleton_Pattern.
19 See wiki.forum.nokia.com/index.php/KIS001019_-_Open_C++:_Destructor_of_a_gl-obal_object_is_not_called.
not a specialization of MRadio and the concrete class instead inherits from them separately and implements both interfaces:
class MRadio {
public:
class MClock {
public:
virtual void CurrentTimeL(TTime& aTime) = 0; };
class CClockRadio : public CBase, public MRadio, public MClock
public:
// From MClock void CurrentTimeL(TTime& aTime);
// Other functions omitted for clarity };
For M class inheritance, various combinations of this sort are possible. However, other forms of multiple inheritance can introduce significant levels of complexity if the standard CBase class is used.20 Multiple inheritance from two CBase-derived classes will cause problems of ambiguity at compile time, which can only be solved by using virtual inheritance:
class CClockRadio : public CClock, public CRadio {•••};
void TestMultipleInheritance()
// Does not compile, CClockRadio::new is ambiguous // Should it call CBase::new from CClock or CRadio?
CDerived* derived = new (ELeave) CDerived;
20See the May 2008 Code Clinic article at developer.symbian.org/wiki/index.php/ Mixin_Inheritance_and_the_Cleanup_Stack.
Post a comment