virtual function default arguments behaviour

The standard says (8.3.6.10):

A virtual function call (10.3) uses
the default arguments in the
declaration of the virtual function
determined by the static type of the
pointer or reference denoting the
object. An overriding function in a
derived class does not acquire default
arguments from the function it
overrides.

This means, since you are calling print through a pointer of type B, it uses the default argument of B::print.

Leave a Comment