Class Derivation Hell

I have a base virtual class who needs to be derived from two classes, who need to be BOTH derived from a single class.

Example code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Base {
    virtual ~Base(){}
};

class DerivedA : public Base {
    virtual ~DerivedA(){}
};

class DerivedB : public Base {
    virtual ~DerivedB(){}
};

class FinalClass : public DerivedA, DerivedB {
    virtual ~FinalClass(){}
};


Should I expect this to work?
What's the correct way otherwise?
You have two instances of Base class being dirived when it reaches the FinalClass

Shouldn't it be:

1
2
3
4
5
6
7
class DerivedA : public virtual Base {
    virtual ~DerivedA(){}
};

class DerivedB : public virtual Base {
    virtual ~DerivedB(){}
};



http://stackoverflow.com/questions/21558/in-c-what-is-a-virtual-base-class

*link
http://en.wikipedia.org/wiki/Virtual_inheritance
Last edited on
Topic archived. No new replies allowed.