Andre Poenitz wrote:
> Have you checked this work?
I have now. 

> If not one has probably derive "diamondlike"
Yes, that would work too.


The code below is interesting in that Derived1 needs to explicitly 
redefine data() or I get an error 
cxx: Error: trial2.C, line 25: object of abstract class
type "Derived1" is not allowed:
            pure virtual function "Base2::data" has no overrider
        Derived1 d1;
-----------------^

But I don't think that this will be a problem in this case. However, 
I'll ponder further.

#include <ostream>

struct Base1 {
        virtual int data() { return 1; }
};

struct Base2 {
        virtual int data() = 0;
        void print() {
                std::cout << "data is " << data() << std::endl;
        }
};

struct Derived1: virtual public Base1, virtual public Base2 {
        virtual int data() { return Base1::data(); }
};


struct Derived2: virtual public Base1, virtual public Base2 {
        virtual int data() { return 2; }
};


int main() {
        Derived1 d1;
        Derived2 d2;

        d1.print();
        d2.print();
}

        
data is 1
data is 2


-- 
Angus

Reply via email to