错误:候选构造函数(隐式移动构造函数)不可行:没有已知的转换
Error:candidate constructor (the implicit move constructor) not viable: no known conversion
我创建了一个具有以下定义的类文件"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(转换为"计算"。
相关文章:
- 构造函数和转换运算符之间的重载解析
- 为什么在使用转换构造函数赋值后调用C++类的析构函数?
- enable_if转换构造函数(静态强制转换,is_base_of)
- 参数包构造函数在类模板中隐藏用户定义的转换
- c++ 构造函数 将 1 个字符串参数转换为 3 个属性
- 复制构造函数隐式转换问题
- 没有合适的构造函数可以从"float"转换为"_D3DCOLORVALUE"
- 如果存在从"双精度"到"T"的转换,则禁用构造函数
- C++隐式构造函数转换,后跟类型向上转换
- 此语法中的构造函数转换错误
- C 操作员在具有构造函数转换时过载
- 如何在允许拷贝限制的同时禁用隐式构造函数转换
- 构造函数转换
- 通过构造函数转换容器
- C++ "没有合适的构造函数可以从<默认构造函数>转换为参数化构造函数
- 多个隐式构造函数转换
- (涉及显式)运算符和构造函数转换的优先级
- 构造函数转换如何在C++中工作
- 如何修复GCC编译中的const char *构造函数转换链错误
- 隐式构造函数转换的编译器优化