When inheriting two base classes, what happens if both have a method with the same name and signature?
class Physics
{
public:
void Update() { std::cout << "Physics!" }
};
class Graphics
{
public:
void Update() { std::cout << "Graphics!" }
};
class Shape : Physics, Graphics
{
};
int main()
{
Shape shape;
shape.Update();
}
What will happen?
Well, first of all your code does not compile regardless of the call to
Update:Updatemember functions lack returns typesShapeinherits privately fromPhysicsandGraphics, soUpdateis inaccessible frommainNow, that being said, what happens when you attempt to call
Updateis an ambiguity which will lead to a compilation error. This ambiguity may be lifted using :