no default constructor exists for class"BASE"是什么错误?

 我来答
malylily
2011-05-20 · TA获得超过1万个赞
知道大有可为答主
回答量:1464
采纳率:0%
帮助的人:560万
展开全部
是电脑术语
error #: no default constructor exists for class " "

A: Why I get this compilation error? line 30: error #2291: no default constructor exists for class "ABC"

B: Obviously the error is telling that class ABC does not have a default constructor.

A: What is default constructor?

B: Default constructor is a constructor with no argument or argument (with default value). Put it in other words, default constrcutor is a constructor that can be called with no argument. For example,

class ABC {
public:
ABC(); // Default constrcutor without argument
};

class ABC {
public:
ABC(int x=0, int y=1); // Default constructor, can be called without argument
};

A: So, we must write default constructor for a class?

B: If you have not write any constrcutor for a class, compiler will implicitly create a default constructor for the class. If you had create a constructor for the class, then its your responsibility to create a default constructor explicitly.

A: ABC class is actually a base class for DEF class. For some reason, I am unable to create a default construcor for ABC class. How do I solve the compilation error?

B: Call the base class constructor in derived class constructor. If you have not call the base class constructor explicitly, compiler automatically call the base class default constructor.

class DEF: public ABC {
public:
DEF(int x);
};

DEF::DEF(int x) : ABC(x,y), _x(x){
}

参考资料: yahoo

本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
jerrying008
2011-05-14 · TA获得超过123个赞
知道答主
回答量:48
采纳率:0%
帮助的人:0
展开全部
不知道您问的是哪方面的错误,但是句法上没有什么错误。好像是电脑术语!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式