简体   繁体   English

在构造函数中,没有匹配的函数调用

[英]in constructor, no matching function call to

My error 我的错误

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)

My code 我的密码

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

I am a little unsure of what exactly it is trying to tell me and what I am doing wrong. 我不确定它到底想告诉我什么,我做错了什么。 I am passing the correct variable types to the class and the correct number of parameters. 我将正确的变量类型传递给类和正确数量的参数。 However it says I am trying to call Window::Window() with no parameters. 但是它说我试图不带参数调用Window::Window() Thanks in advance for any help. 在此先感谢您的帮助。

The class Button compiles just fine, and is almost exactly the same. 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();
        }

Your GridList class has a member variable of type Window . 您的GridList类具有类型为Window的成员变量。 Since all members are (default if unspecified) initialized before the body of the constructor, yours looks similar to this in reality: 由于所有成员(如果未指定,则默认为默认值)在构造函数的主体之前初始化因此实际上您的样子类似于此:

GridList::GridList (...)
 : Window(...), m_tendMenu() //<--here's the problem you can't see

Your member variable is being default initialized, but your Window class has no default constructor, hence the problem. 您的成员变量正在默认初始化,但是您的Window类没有默认构造函数,因此出现了问题。 To fix it, initialize your member variable in your member initializers: 要解决此问题,请在成员初始化程序中初始化您的成员变量:

GridList::GridList (...)
 : Window(...), m_tendMenu(more ...), //other members would be good here, too

The reason your Button class works is because it doesn't have a member of type Window , and thus, nothing being default-initialized when it can't be. 您的Button类起作用的原因是因为它没有Window类型的成员,因此,在不能使用时,不会对其进行默认初始化。

Why are you just calling the constructor in the initlizer list ? 为什么只在初始化器列表中调用构造函数? usually you initialize member variables there so there would be member variable of type window there. 通常,您在那儿初始化成员变量,所以那里会有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) { }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM