#include <iostream>
using namespace std;
class Shape
{
public:
virtual int getS()=0; //纯虚函数不实现,仅声明,留待子类里重写定义
virtual int getC()=0; //含有纯虚函数的类叫做抽象类,仅有纯虚函数的类叫接口
};
class Circle : public Shape
{
private:
float radius;
public:
Circle(float radius){
this->radius=radius; //构造函数(使用类时实例化对象)
}
void func(){
cout << "Hello world" << endl;
}
int getS(){
cout << radius * radius * 3.14 << endl;
return 0;
} //继承重写
int getC(){
cout << radius * 2 * 3.14 << endl;
return 0;
}
};
int main() {
Circle s1(3.f);
cout << "Hello world" << endl;
s1.getC();
s1.getS();
return 0;
}