简体   繁体   English

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

[英]“No matching function call” in constructor

This is the constructor declaration that I have in my "solver.h" file. 这是我在“solver.h”文件中的构造函数声明。

Solver(const Board &board_c, int max_moves_c);

When trying to compile I get the following error... 在尝试编译时,我收到以下错误...

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)

And then it lists the candidates which are the Board constructors. 然后列出了作为董事会建设者的候选人。

I'm not sure what I'm doing wrong as I see no reason why I should be getting this error. 我不确定我做错了什么,因为我认为没有理由为什么我应该得到这个错误。

I am compiling with g++. 我用g ++编译。

error: no matching function for call to 'Board::Board()' 错误:没有用于调用'Board :: Board()'的匹配函数

means that class Board is missing the deafault constructor. 意味着类Board缺少deafault构造函数。 In the constructor of Solver you are probably doing something like: Solver的构造函数中,您可能正在执行以下操作:

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

so you either have to define the default constructor or invoke the appropriate constructor with some arguments. 所以你要么必须定义默认的构造函数,要么用一些参数调用相应的构造函数。

"And then it lists the candidates which are the Board constructors." “然后它列出了作为董事会建设者的候选人。”

That's because compiler wants to help you so it lists possible constructors that are actually available (defined). 那是因为编译器想要帮助你,所以它列出了实际可用(定义)的可能的构造函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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