There is a C ++ program:
# include <iostream>
using namespace std;
class base
{
public:
base()
{
cout<<"base"<<endl;
f();
}
virtual void f() {
cout<<"base f"<<endl;
}
};
class derive: public base
{
public:
derive()
{
cout<<"derive"<<endl;
f();
}
void f() {
cout<<"derive f"<<endl;
}
};
int main()
{
derive d;
return 1;
}
and outputs:
base
base f
derive
derive f
I wonder why the base f appears?
I want the constructor to expand to:
cout<<"base"<<endl;
this.f();
But this should indicate in order to determine why the base f is being printed?
source
share