在构造函数中,没有对的匹配函数调用
in constructor, no matching function call to
我的错误
gridlist.h: In constructor ‘GridList::GridList(WINDOW*, int, int, int, int, int)’:
gridlist.h:11:47: error: no matching function for call to ‘Window::Window()’
gridlist.h:11:47: note: candidates are:
window.h:13:3: note: Window::Window(WINDOW*, int, int, int, int, int)
我的代码
GridList(WINDOW *parent = stdscr, int colors = MAG_WHITE, int height = GRIDLIST_HEIGHT, int width = GRIDLIST_WIDTH, int y = 0, int x = 0)
: Window(parent, colors, height, width, y, x) {
this->m_buttonCount = -1;
m_maxButtonsPerRow = ((GRIDLIST_WIDTH)/(BUTTON_WIDTH+BUTTON_SPACE_BETWEEN));
this->m_buttons = new Button *[50];
refresh();
}
我有点不确定它到底想告诉我什么,以及我做错了什么。我将正确的变量类型和正确数量的参数传递给类。然而,它说我正在尝试在没有参数的情况下调用Window::Window()
。提前感谢您的帮助。
Button类编译得很好,而且几乎完全相同。
Button(WINDOW *parent = 0, int colors = STD_SCR, int height = BUTTON_WIDTH, int width = BUTTON_HEIGHT, int y = 0, int x = 0)
: Window(parent, colors, height, width, y, x) {
this->refresh();
}
GridList
类有一个类型为Window
的成员变量。由于所有成员(如果未指定,则为默认值)都是在构造函数的主体之前初始化的,所以您的成员在现实中看起来与此类似:
GridList::GridList (...)
: Window(...), m_tendMenu() //<--here's the problem you can't see
您的成员变量正在进行默认初始化,但Window
类没有默认构造函数,因此出现了问题。要修复它,请在成员初始化器中初始化您的成员变量:
GridList::GridList (...)
: Window(...), m_tendMenu(more ...), //other members would be good here, too
Button
类工作的原因是它没有Window
类型的成员,因此,当它不能初始化时,没有任何默认初始化。
为什么只调用initlizer列表中的构造函数?通常您在那里初始化成员变量,这样就会有window类型的成员变量。
GridList(WINDOW *parent = stdscr, int colors = MAG_WHITE,
int height = GRIDLIST_HEIGHT, int width = GRIDLIST_WIDTH, int y = 0, int x = 0)
: m_window(parent, colors, height, width, y, x) { }
相关文章:
- 在c++中使用向量时,如何调用构造函数和析构函数
- C++:考虑但不调用构造函数的特殊性
- 对象实例化调用构造函数的次数太多
- 我使用向量来创建类对象列表.初始化向量时如何使用参数调用构造函数?
- C ++:通过大括号调用构造函数?
- 不能调用构造函数
- 赋值 boost::intrusive_ptr 而不调用构造函数?
- 将成员函数作为构造函数参数调用时出错 "Variable is not a type name"
- 当我尝试从成员函数调用构造函数时,为什么IDE会发出警告
- 从复制构造函数调用构造函数
- 从同一类的另一个构造函数调用构造函数
- 从另一个成员函数/构造函数调用C++构造函数是否执行初始值设定项列表
- 通过引用从函数调用C++构造函数
- 从不同类的构造函数调用构造函数
- 错误:没有匹配的函数调用'构造函数'注意:候选函数是:
- 从构造函数调用构造函数
- 用数组初始化从另一个构造函数调用c++构造函数
- 从成员函数调用构造函数
- 在c++中从另一个构造函数调用构造函数时出错
- 可以从静态函数调用构造函数