在调用中使用 std::vector<double> 但收到有关 std::vector<double, std::allocator<double> > 正在使用的错误

不朽

我有一个创建向量的函数,然后使用该向量作为输入调用类构造函数,但它返回一个错误说

undefined reference to Class::Class(std::vector<double, std::allocator<double> >)

该类有一个构造函数

std::vector<double>

但不是

std::vector<double, std::allocator<double> >

一些示例代码:

std::vector<double> x1;
std::vector<double> x2;
std::vector<double> myvec;
double thisX;

for (int i=0; i<x1.size(); i++ {
    thisX = x1[i];
    myvec.push_back(thisX);
}
for (int i=0; i<x2.size(); i++ {
    thisX = x2[i];
    myvec.push_back(thisX);
}

Class MyClass( myvec );
// has a constructor for std::vector<double>
// compiler throws the undefined reference to 
// Class::Class(std::vector<double, std::allocator<double> >)

任何见解表示赞赏!如果不明显的话,我对 C++ 比较陌生。

马克西姆·叶戈鲁什金

std::vector<double>是 的缩写形式std::vector<double, std::allocator<double> >,因为第二个模板参数std::vector<>默认为std::allocator<T>

错误的原因是不同的。


undefined reference to Class::Class错误意味着有此构造函数声明但没有定义

你可能不与目标文件或链接库定义Class::Class需要链接它才能解决未定义的引用。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章