Here is the class definition:
class Shape { public:
virtual void draw() = 0; ...
};
class Circle : public Shape {
public:
void draw() { ... }
... };
class Rectangle : public Shape { public:
void draw() { ... } ...
};
class Square : public Rectangle {
public:
void draw() { ... }
... };
And here is the client code:
Square* sq = new Square;
Rectangle* rect = new Rectangle;
Shape* ptr_shape;
ptr_shape = sq;
ptr_shape->draw();
rect->draw();
A book that I was reading said the last statement is static binding:
However, the statement still looks dynamic binding to me because rect->draw
should be called by the pointer in the "vtable" of rect
in run-time.
Does anyone have ideas about whether the rect->draw
is static binding or dynamic binding?
final
would prevent it from compiling. It forbids overriding rather than stops it. – Piton