This is a continuation of my prior question. Note that the code below makes a virtual call at p->f(1.0)
printing Derived::f(double)
.
#include <iostream>
#include <complex>
using namespace::std;
class Base
{
public:
virtual void f(double);
virtual ~Base() {};
};
void Base::f(double) { cout << "Base::f(double)\n"; }
class Derived : public Base {
public:
void f(std::complex<double>);
void f(double);
};
void Derived::f(std::complex<double>) { cout << "Derived::f(complex)\n"; }
void Derived::f(double) { cout << "Derived::f(double)\n"; }
int main()
{
Derived* p = new Derived;
p->f(1.0);
delete p;
}
If I just eliminate the member function void f(double);
in Derived
, the code makes a static call to Derived::f(std::complex<double>)
.
What was it that made the compiler change from a dynamic call in the first example to a static call in the second? I would appreciate some quote from the Standard.
Edit:
The answers to the question to which this was considered a dup don't cite the Standard, as I asked above. Thanks.