2017-02-13 57 views
0

我想要一个简单的方法来复制使用Eigen3 MatrixXd类的矩阵。为此,我使用新方法创建头文件,并使用宏uEIGEN_MATRIXBASE_PLUGIN将其包含在编译中。如何向Eigen3基类添加新方法?

我想创建名为copyMatrix()的方法,其简单地等同于做 A = B 但在这种格式: A.copyMatrix(B)。

当我尝试将其与下面的代码的代码:

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

我有编译错误,如: 错误C2678:二进制“=”:没有操作员发现这需要类型的左侧操作数'const Eigen :: Matrix'(或者没有可接受的转换)

这是正确的语法吗?

回答

1

这是因为你的方法copyMatrixconst,只是将其删除:

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