#include <iostream>

using namespace std;

class Base {
public:
    virtual void func1() {}
    virtual void func2() {}
    virtual void func3() {}
    virtual ~Base() {}
};

template<class B> class Derived1 : public B {
public:
    void func1() {
        cout << "Derived1" << endl;
        B::func1();
    }
};

template<class B> class Derived2 : public B {
public:
    void func2() {
        cout << "Derived2" << endl;
        B::func2();
    }
};

template<class B> class Derived3 : public B {
public:
    void func3() {
        cout << "Derived3" << endl;
        B::func3();
    }
};

int main() {
    typedef Derived1<Derived2<Base>> Foo;
    Base *foo = new Foo;
    foo->func1();
    foo->func2();
    foo->func3();  // do nothing
    cout << "---------\n";
    typedef Derived2<Derived3<Base>> Qoo;
    Base *qoo = new Qoo;
    qoo->func1();  // do nothing
    qoo->func2();
    qoo->func3();
    cout << "---------\n";
    typedef Derived1<Derived1<Base>> Hoo;
    Base *hoo = new Hoo;
    hoo->func1();  // output twice
}
