A virtual function call 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.
[ Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
struct A {
virtualvoid f(int a = 7);
};
struct B : public A {
void f(int a);
};
void m() {
B* pb = new B;
A* pa = pb;
pa->f(); // OK, calls pa->B::f(7)
pb->f(); // error: wrong number of arguments for B::f()
}
— end example ]
- IS (emphasis was added)
Btw, the last line of main() - delete object; - will result in undefined behaviour.