#include<iostream> using namespace std; class CPoint { private: double x,y; public : CPoint (double i,double j); double Getx(); double Gety(); double Setpoint(double i,double j); }; class CShape { public: CPoint point; virtual double Area() { return 0.0; } }; class CCircle:public CShape { public: float r; CCircle(CPoint p1,float r=2):CShape(),r(r){} double Area() { return 3.14*r*r; } }; class CRect:public CShape { public: double x,y; CRect(CPoint p1,double x=2,double y=1):CShape(),x(x),y(y){} double Area() { return x*y; } }; class CEll:public CShape { public: double x,y; CEll(CPoint p1,double x=2,double y=1):CShape(),x(x),y(y){} double Area() { return 3.14*x*y; } }; int main() { return 0; }In constructor 'CCircle::CCircle(CPoint, float)': /storage/emulated/0/Code/Project/CPlusPlus/作业3/main.cpp:26:46: error: use of deleted function 'CShape::CShape()' CCircle(CPoint p1,float r=2):CShape(),r(r){} ^ compilation terminated due to -Wfatal-errors. 怎么修改?
时间: 2024-03-19 17:43:38 浏览: 69
在CShape的构造函数中添加一个默认构造函数即可。代码如下:
```
#include<iostream>
using namespace std;
class CPoint {
private:
double x,y;
public :
CPoint (double i,double j);
double Getx();
double Gety();
double Setpoint(double i,double j);
};
class CShape {
public:
CPoint point;
CShape(){} // 添加默认构造函数
virtual double Area()
{
return 0.0;
}
};
class CCircle:public CShape {
public:
float r;
CCircle(CPoint p1,float r=2):CShape(),r(r){}
double Area()
{
return 3.14*r*r;
}
};
class CRect:public CShape {
public:
double x,y;
CRect(CPoint p1,double x=2,double y=1):CShape(),x(x),y(y){}
double Area()
{
return x*y;
}
};
class CEll:public CShape {
public:
double x,y;
CEll(CPoint p1,double x=2,double y=1):CShape(),x(x),y(y){}
double Area()
{
return 3.14*x*y;
}
};
int main() {
return 0;
}
```
阅读全文