将特征矩阵传递给函数时出错 C++:"no instance of overloaded function matches the argument list"
Error passing Eigen matrix to a function in C++: "no instance of overloaded function matches the argument list"
我有一个运行良好的脚本,但当我尝试用相同的脚本编写函数时,我会收到错误"没有重载函数的实例";aapx"匹配参数列表";。
我知道Eigen::矩阵应该总是通过引用函数来传递,所以我这样做了,我想问题可能是我正在初始化Eigen::Matrix<std::complex<double>
并传递Eigen::MatrixXcd
,但这似乎也不能解决错误。
功能
void aapx(const Eigen::Ref<const Eigen::MatrixXcd>& uh, Eigen::Ref<const Eigen::MatrixXcd>& vh, Eigen::Ref<const Eigen::MatrixXcd>& ph){
//some calculations
}
主要代码看起来像:
static const int nx = 10;
static const int ny = 10;
Eigen::Matrix<std::complex<double>, (ny+1), (nx)> uh;
uh.setZero();
Eigen::Matrix<std::complex<double>, (ny+1), (nx)> vh;
vh.setZero();
Eigen::Matrix<std::complex<double>, (ny+1), nx> ph;
ph.setZero();
aapx(uh,vh,ph); //ERROR
如果需要,我可以发布完整的代码。完整错误:
no instance of overloaded function "aapx" matches the argument list
argument types are: (Eigen::Matrix<std::_Complex<double>, 11, 10, 0, 11, 10>, Eigen::Matrix<std::_Complex<double>, 11, 10, 0, 11, 10>, Eigen::Matrix<std::_Complex<double>, 11, 10, 0, 11, 10>)
您的第三个参数ph
需要是
Eigen::Ref<const Eigen::MatrixXcd> ph
(无参考(而非
Eigen::Ref<const Eigen::MatrixXcd>& ph
因为CCD_ 4已经是引用。您不想更改引用,而是想更改矩阵。
看看这个答案:正确使用特征::Ref<gt;类
相关文章:
- C++ Singleton - Prevent ::instance() to variable
- Usages of std::move
- 使用 [] 运算符时"binding reference of type discards qualifiers"
- 如何处理 c++ 中类实现中的"invalid use of non-static data member"?
- 具有变量Number of Arguments的std::函数的矢量
- "terminate called after throwing an instance of std::invalid_argument' what(): stoi ?"
- cin.get() 导致"no instance of overloaded function"错误
- 尝试在虚幻引擎中通过C++添加视口时出错"No instance of overloaded function CreateWidget"
- 3D 矢量 - "No instance of overload function?"
- 不能使用矢量::插入"no instance of overloaded function..."
- 矩阵类:"No instance of overloaded function push_back matches the argument list"
- 如何修复矢量push_back中的"no instance of overloaded function"?
- "No instance of overload function"
- 显示"terminate called after throwing an instance of 'std::bad_alloc'"时出错
- C++向量和错误"no instance of overloaded function"
- 使用字符串向量初始值设定项时,我收到运行时错误"terminate called after throwing instance of `std::length_error`"
- 如何修复 cin.getline 的"No instance of overloaded function"错误?
- "more than one instance of overloaded function " 标准::p ow " matches the argument list"
- 为什么我在投入析构函数时总是"terminate called after throwing an instance of..."?
- 在C++中创建"new instance of object"方法