This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Pass an Eigen::Matrix object as argument to a function

Tags: None
(comma "," separated)
sylvainrousseau
Registered Member
Posts
7
Karma
0
Hi !

I fail to compile a simple call to a template function which takes an Eigen:: Matrix as argument.
May I ask you some hint ?

See below the code :

Code: Select all
template <typename DerivedA>
MatrixBase<DerivedA>& tst12(const MatrixBase<DerivedA>& M )
{
  return M.transpose();
}

int main ()
{
  Matrix<double, 12,4> M;
  tst12(M);
 
return 0;
}


See below the compiler error :

src/tstEigen.cpp: In instantiation of ‘Eigen::MatrixBase<Derived>& tst12(const Eigen::MatrixBase<Derived>&) [with DerivedA = Eigen::Matrix<double, 12, 4>]’:
src/tstEigen.cpp:324:10: required from here
src/tstEigen.cpp:316:22: error: invalid initialization of non-const reference of type ‘Eigen::MatrixBase<Eigen::Matrix<double, 12, 4> >&’ from an rvalue of type ‘Eigen::DenseBase<Eigen::Matrix<double, 12, 4> >::ConstTransposeReturnType {aka const Eigen::Transpose<const Eigen::Matrix<double, 12, 4> >}’
return M.transpose();

Thanks for helping !

Sylvain
sylvainrousseau
Registered Member
Posts
7
Karma
0
Sorry, the problem is fixed.
It was'nt an issue related to the argument passing, but it was due to the function code.
I fixed the code with :

Code: Select all
template <typename DerivedA>
void tst12(const MatrixBase<DerivedA>& inM, MatrixBase<DerivedA>& outM )
{
  outM = inM;
}

int main ()
{
  const Matrix<double, 12,4> inM;
  Matrix<double, 12,4> outM;
  tst12( inM, outM );
  return 0;
}



Sorry for the disturbance.


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]