0

我的错误

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();
        }
4

2 回答 2

3

你的GridList类有一个 type 的成员变量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类工作的原因是因为它没有 type 的成员Window,因此,当它不能被默认初始化时,没有任何东西被默认初始化。

于 2012-07-21T00:13:14.147 回答
-2

你为什么只是在初始化列表中调用构造函数?通常你在那里初始化成员变量,所以那里会有 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) { }
于 2012-07-20T23:26:41.610 回答