类中的重写
class Fater{
void Show()
{
cout<<"class Father"<<endl;
}
};
class CSon:class Father{
void Show()
{
cout<<"class CSon"<<endl;
};
int main(){
Father* fa = new Cson;
fa->Show();
}
//输出结果时: class Father
但如果想要用父类指针调用子类函数,这时候就需要用virtual来实现多态
class Fater{
virtual void Show()
{
cout<<"class Father"<<endl;
}
};
class CSon:class Father{
void Show()
{
cout<<"class CSon"<<endl;
};
int main(){
Father* fa = new Cson;
fa->Show();
}
//输出结果时: class CSon