user1240679
user1240679

Reputation: 6979

Ambiguous members in multiple inheritance

I am trying to create a new class in my program which is being extended from two inbuilt classes in a framework.

class Node{
    setPosition();
    draw();
};

class Rectangle{
    setPosition();
    draw();
};

class CustomShape : public Node, public Rectangle{

};

In main program, if I try to write something like CustomShape a and

a.setPosition();
a.draw();

I get compile time errors with ambiguous calls. How can I resolve this?

Upvotes: 1

Views: 132

Answers (1)

Kerrek SB
Kerrek SB

Reputation: 477060

Add explicit qualifications:

a.Node::setPosition();
a.Rectangle::setPosition();

a.Node::draw();
a.Rectangle::draw();

Alternatively you can insert a cast:

static_cast<Node&>(a).setPosition();

But that's less attractive.

Upvotes: 3

Related Questions