返回信息流class point {
protected :
int x,y;
public:
point( int a,int b) {x=a;y=b;}
int GetX(){ return x;}
int GetY() {return y;}
};
class Circle :public point
{
protected :
int radius;
public :
Circle(int a=0,int b=0,int r=0) {radius=r;};
int getRadius(){ return radius;};
};
int main()
{
Circle c(100,150,200);
cout<<c.getRadius()<<endl;
printf("x=%d ,y=%d,r=%d",c.GetX(),c.GetY(),c.getRadius());
system("pause");
return 0;
}
编译的时候出现说 error C2512: 'point' : no appropriate default constructor available ,不是派生类自动调用基类的构造函数么,出现这个错误是为什么呢?
这是一条镜像帖。来源:北邮人论坛 / cpp / #9359同步于 2008/7/8
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
请各位同学看下这个问题
w6459
2008/7/8镜像同步5 回复
订阅后,新回复会通过你的通知中心匿名送达。
5 条回复
在circle类的构造函数中,用初始化表是可以的
Circle(int a=0,int b=0,int r=0):point(a,b),radius(r) {}
【 在 w6459 的大作中提到: 】
: class point {
: protected :
: int x,y;
: ...................
派生类默认调用的是基类的默认构造,也就是无参构造。。。
【 在 w6459 (vicent) 的大作中提到: 】
: class point {
: protected :
: int x,y;
: ...................
re
【 在 hokkien (我脱,我脱,我脱脱脱!) 的大作中提到: 】
: 派生类默认调用的是基类的默认构造,也就是无参构造.其实也很好理解,想下,如果不是这样的话,那么一但基类定义很多个构造函数,那么派生类要调用哪一个呢?