I have this simple testing code:
class father{
public:
father()= default;
virtual void func(){
cout <<"father" << endl;
}
};
class child:public father{
public:
child() = default;
void func(){
cout << "child" << endl;
}
};
int main(){
father* fptr = new child;
auto s = *fptr; //why type of s will be father?
(*fptr).func(); //child
s.func(); //father
return 0;
}
I don't know why type s will be father
. If dereference a pointer will eliminate the polymorphism, why (*fptr).func();
works fine?