错误:候选构造函数(隐式移动构造函数)不可行:没有已知的转换

Error:candidate constructor (the implicit move constructor) not viable: no known conversion

本文关键字:构造函数 转换 不可行 移动 候选 错误      更新时间:2023-10-16

我创建了一个具有以下定义的类文件"Heuristic.hpp":

#include <iostream>
#include <vector>
#include <chrono>
#include <cstdint>
#include <cmath>
#include <limits>
#include "csv.hpp"
#include "mdl.hpp"
class Computation {
public:
     Computation(const int n,const int noRows, MDL mdl) {

        std::cout << "Constructor successfully made" << std::endl;
    }
    double heuristic() {
        return 0;
    }

private:
    std::vector<uint64_t> MDL_RawIndex_;
    std::vector<std::vector<uint64_t>> factValues_;
    std::vector<std::vector<uint64_t>> MDL_Index_;
    std::vector<std::vector<double>> MDL_RawScore_;
    std::vector<std::vector<double>> MDL_Score_;
    std::vector<uint64_t> MDL_Score_Length_;
    std::vector<double> bestScore_;
    int n_ = 0;
    int noRows_ = 0;
};

在主代码文件"example.cpp"上,当我尝试创建对象时,它会抛出错误。代码如下:当我尝试创建在上一个文件中声明的类 Computing 的对象时出现错误。在这种情况下,不会调用构造函数:

#include <iostream>
#include <vector>
#include "csv.hpp"
#include "mdl.hpp"
#include "Heuristic.hpp"
Computation bootup() {
    std::string in = "/Users/skx/Google Drive/Semester3_Fall15/CSE603/HeuristicSearchPy/child.csv";
    int noRows = 4000;
    std::vector<signed char> Data;
    int n = 20;
    if (!read_csv(in, n, noRows, Data)) {
        std::cout << "error: could not read input" << std::endl;
        return -1;
    }
    MDL mdl(n, noRows, Data);
    Computation h(n,noRows,mdl);   //This object creation is where error is occurring 
    return h;
    }

int main(int argc,char* argv[]) {

return 0;
}

错误日志:

note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'Computation &&' for 1st argument
class Computation {
      ^
/Users/skx/Google Drive/Semester3_Fall15/CSE603/HeuristicSearchPy/Heuristic.hpp:11:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const Computation &' for 1st argument
class Computation {

您没有在错误消息中给出导致问题的行号,所以这只是一个猜测,但我认为问题出在"return -1"行上。

试图找到一个具有单个参数的构造函数,它唯一能找到的是隐式复制和移动构造函数。错误消息告诉您它尝试使用这些,但无法从类型"int"(-1(转换为"计算"。