错误:没有匹配的函数调用 [英] error: no matching function for call to
本文介绍了错误:没有匹配的函数调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
遇到我的错误...
在构造函数中NumGame :: NumGame(int&)':
错误: 'category :: Category()'
"In constructor 'NumGame::NumGame(int&)': error: no matching function for call to 'Category::Category()'"
Ive看了一些类似的问题,但似乎找不到答案。我有一个基类Category,NumGame是继承自它,但不能编译。
Ive looked at a few similar questions here but cant seem to find an answer. I have a base class Category and NumGame is inherited from it but wont compile.
class Category {
public:
void virtual selection(int&);
Category(int&);
virtual ~Category(){};
private:
int myRandNum;
};
Category::Category(int& a){
myRandNum = a;
}
void Category::selection(int& a){
cout << "I am NumGame version number... " << a << endl;
cout << "Now Im playing... " << myRandNum << endl;
}
class NumGame : public Category {
public:
void selection(int&);
NumGame(int&);
~NumGame(){};
private:
int myRandNum;
};
NumGame::NumGame(int& b){
myRandNum = b;
}
void NumGame::selection(int& b) {
}
推荐答案
类别
没有默认构造函数,因此您需要提供参数构建基本对象
的
基础对象:
Category
does not have a default constructor, so you need to supply arguments when constructing the Category
base object of NumGame
:
NumGame::NumGame(int& b) :
Category(b)
{
myRandNum = b;
}
这篇关于错误:没有匹配的函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文