2013-10-22 33 views
10

這是我在「solver.h」文件中的構造函數聲明。構造函數中的「No matching function call」

Solver(const Board &board_c, int max_moves_c); 

當試圖編譯我碰到下面的錯誤...

solver.cpp: In constructor 'Solver::Solver(const Board&, int)': 
solver.cpp:6:55: error: no matching function for call to 'Board::Board()' 
    Solver::Solver(const Board &board_c, int max_moves_c) 

然後它列出了本屆董事會建設者候選人。

我不知道我在做什麼錯誤,因爲我沒有理由爲什麼我應該得到這個錯誤。

我正在用g ++編譯。

回答

14

error: no matching function for call to 'Board::Board()'

表示類Board缺少默認構造函數。在Solver構造你可能做這樣的事情:

Solver::Solver(const Board &board_c, int max_moves_c) { 
    Board b; // <--- can not construct b because constructor is missing 
    ... 
} 

,所以你要麼必須定義默認構造函數或某些參數調用適當的構造函數。

"And then it lists the candidates which are the Board constructors."

這是因爲編譯器想幫助你,所以它列出了實際可用(定義)的可能構造函數。

相關問題