将特征矩阵传递给函数时出错 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"

本文关键字:of instance no overloaded function list argument the matches C++ 特征      更新时间:2024-09-30

我有一个运行良好的脚本,但当我尝试用相同的脚本编写函数时,我会收到错误"没有重载函数的实例";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;类