0
votes

I want to a simple method to copy a matrix using Eigen3 MatrixXd class. For that I create a header file with the new method and I use the macro uEIGEN_MATRIXBASE_PLUGIN to include in the compilation.

I want to create a method named copyMatrix() that simply is identical to do A = B but in this format: A.copyMatrix(B).

When I try to code it with the following code:

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

I have compilation errors such as: error C2678: binary '=': no operator found which takes a left-hand operand of type 'const Eigen::Matrix' (or there is no acceptable conversion)

Which is correct syntax for this?

1

1 Answers

1
votes

This is because your method copyMatrix is const, just remove it:

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