no default constructor exists for class"BASE"是什么错误?
2个回答
展开全部
是电脑术语
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){
}
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
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不知道您问的是哪方面的错误,但是句法上没有什么错误。好像是电脑术语!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询