user19783152
user19783152

Reputation: 51

How do I remove this ambiguity in hybrid inheritance?

I have a case in project where I need to inherit an abstract class virtually into two different classes which are again inherited into final class but the compiler keeps showing me this error

 error C2250: 'D': ambiguous inheritance of 'B &A::doit(void)'

How do I remove such error , class sample is as follow

class A {
public:
    virtual A& doit() = 0;
};

class B :virtual public A {
public:
    virtual B& doit() {
        cout << "B";
        return *this;
    }
};
class C : virtual public A {
public:
    C& doit() {
        cout << "C";
        return *this;
    }
};
class D : public B, public C {
public:
    D& doit() {
        cout << "D";
        return *this;
    }
};

I have tried deleting base class functions first but it does not seem to work.

Upvotes: 5

Views: 43

Answers (0)

Related Questions