簡體   English   中英

在構造函數中,沒有匹配的函數調用

[英]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類型的成員,因此,在不能使用時,不會對其進行默認初始化。

為什么只在初始化器列表中調用構造函數? 通常,您在那兒初始化成員變量,所以那里會有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