如何将新方法添加到 Eigen3 基类



我想要一个简单的方法来使用Eigen3 MatrixXd类复制矩阵。为此,我使用新方法创建了一个头文件,并使用宏uEIGEN_MATRIXBASE_PLUGIN包含在编译中。

我想创建一个名为 copyMatrix(( 的方法,它与 do 相同A = B但以这种格式:A.复制矩阵(B(.

当我尝试使用以下代码对其进行编码时:

template<typename OtherDerived>
inline void copyMatrix(const MatrixBase<OtherDerived>& other) const
{
    derived() = other.derived();
}

我有编译错误,例如: 错误 C2678:二进制"=":未找到采用类型为"const Eigen::Matrix"的左操作数的运算符(或者没有可接受的转换(

哪个语法是正确的?

这是因为您的方法copyMatrix const,只需将其删除即可:

template<typename OtherDerived>
inline void copyMatrix(const MatrixBase<OtherDerived>& other)
{
    derived() = other.derived();
}

最新更新