问题不要发图片,拷贝粘贴发文字。
#include <iostream>
using namespace std;
class shape
{
public:
virtual void show() = 0;
virtual double peri() = 0;
};
class circle : public shape
{
int r = 0;
public:
const double PI = 3.14;
circle(int r) : r(r)
{
}
double peri()
{
return 2 * PI * r;
}
void show()
{
cout << "圆的半径=" << r << endl;
cout << "圆的周长=" << peri() << endl;
}
};
int main()
{
shape *pS;
circle a1(2);
pS = &a1;
pS->show();
}