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

时间:2016-02-17 16:12:21

标签: c++ c++11

我创建了一个类文件" 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;

};

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

#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 {

1 个答案:

答案 0 :(得分:0)

你没有在错误信息中给出导致问题的行号,所以这只是猜测,但我认为问题出在&#34;返回-1&#34;线。

它试图找到一个带有单个参数的构造函数,并且它唯一可以找到的是隐式复制和移动构造函数。错误消息告诉您它尝试使用这些,但无法转换类型&#34; int&#34; (-1)到&#34;计算&#34;。