这句话怎么解释?
这句话怎么解释?parent *p=new son(); 请指教#include<iostream>
using namespace std;
class parent
{
public:
virtual void foo()
{
cout<<"foo from parent."<<endl;
}
void foo1()
{
cout<<"foo1 from parent."<<endl;
}
};
class son:public parent
{
public:
void foo()
{
cout<<"foo from son."<<endl;
}
void foo1()
{
cout<<"foo1 from son."<<endl;
}
};
int main()
{
parent *p=new son();
p->foo();
p->foo1();
return 0;
}