为什么编译(c ++ 特征)"错误 C2659:'=':函数作为左操作数"后会出现错误?

Why errors occur after compilation(c++ eigen) “error C2659: '=' : function as left operand”?

本文关键字:错误 操作数 函数 C2659 特征 编译 为什么      更新时间:2023-10-16
x1.real = x;
x1(k-1).imag = h;
A.col(k-1) = x1.imag / h;

我已经用 c++ 编写了一个带有特征库的矩阵运算程序,但错误发生在这些行中。我们应该如何纠正它?多谢!

#include "stdafx.h"
#include "iostream"
#include "Eigen/Dense"
using namespace std;
using namespace Eigen;
void jaccsd(Vector3d z, Matrix3d A, Vector3d x)
{
    int m, n,k;
    double h;
    z = x;
    n = 3;
    m = 3;
    A = MatrixXd::Zero(3, 3); 
    h = n*0.0001;
    for (k = 1; k <= n; k++)
    {
        Vector3cd x1;
        x1.real = x;
        x1(k-1).imag = h;
        A.col(k-1) = x1.imag / h; 
    }
}

realimagVector3cd的成员函数而不是数据成员,即你需要写

x1.real() = x;

如果您只想分配x1的实际部分.你也可以写

x1 = x;

如果还想将虚部设置为零。在您的代码中,虚部将未初始化。

这同样适用于:

A.col(k-1) = x1.imag() / h; 
相关文章: