【问题标题】:"No matching function call" in constructor构造函数中的“没有匹配的函数调用”
【发布时间】:2013-10-31 16:35:18
【问题描述】:

这是我在“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++ 编译。

【问题讨论】:

    标签: c++ function object constructor matching


    【解决方案1】:

    错误:没有匹配的函数调用'Board::Board()'

    表示Board 类缺少默认构造函数。在Solver 的构造函数中,您可能正在执行以下操作:

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

    所以您要么必须定义默认构造函数,要么使用一些参数调用适当的构造函数。

    “然后它列出了董事会建设者的候选人。”

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

    【讨论】:

      猜你喜欢
      • 2015-09-21
      • 1970-01-01
      • 1970-01-01
      • 2020-01-22
      • 2012-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-09
      相关资源
      最近更新 更多