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

Jon*_*ona 10 c++ constructor function object matching

这是我在"solver.h"文件中的构造函数声明.

Solver(const Board &board_c, int max_moves_c);
Run Code Online (Sandbox Code Playgroud)

在尝试编译时,我收到以下错误...

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)
Run Code Online (Sandbox Code Playgroud)

然后列出了作为董事会建设者的候选人.

我不确定我做错了什么,因为我认为没有理由我应该得到这个错误.

我用g ++编译.

Lih*_*ihO 15

错误:没有用于调用'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
    ...
}
Run Code Online (Sandbox Code Playgroud)

所以你要么必须定义默认的构造函数,要么用一些参数调用相应的构造函数.

"然后它列出了作为董事会建设者的候选人."

那是因为编译器想要帮助你,所以它列出了实际可用(定义)的可能的构造函数.