简体   繁体   中英

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. Thanks in advance for any help.

The class Button compiles just fine, and is almost exactly the same.

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 . 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. 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.

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.

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) { }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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