[英]“No matching function call” in constructor
這是我在“solver.h”文件中的構造函數聲明。
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 ++編譯。
錯誤:沒有用於調用'Board :: Board()'的匹配函數
意味着類Board
缺少deafault構造函數。 在Solver
的構造函數中,您可能正在執行以下操作:
Solver::Solver(const Board &board_c, int max_moves_c) {
Board b; // <--- can not construct b because constructor is missing
...
}
所以你要么必須定義默認的構造函數,要么用一些參數調用相應的構造函數。
“然后它列出了作為董事會建設者的候選人。”
那是因為編譯器想要幫助你,所以它列出了實際可用(定義)的可能的構造函數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.