#include<iostream>
#include<string>
using namespace std;
/**
函数重定义,子类重写父类方法(Override)
*/
class GeometricObject{
public:
string toString()
{
return "我是Parents类toString方法";
}
};
class Circle:public GeometricObject
{
public:
string toString()
{
return "我是Child类toString方法";
}
void display()
{
cout<<toString();
}
};
int main()
{
Circle circle;
cout<<"circle:\t"<<circle.toString()<<endl;
cout<<"GeometricObject:\t"<<circle.GeometricObject::toString();
return 0;
}
子类调用已重写的父类方法 -- demo
最新推荐文章于 2021-07-01 08:57:04 发布