[eigen] How to return an Eigen matrix

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Hi all,

 I am new to Eigen so I am sorry for my naive question. I am trying to
write a function which will return an Eigen template matrix (see code
below). In my code func2 works fine, however, func1 does not. The g++
compiler complain that there is no matching function for call to func1.

What should I do to return an Eigen matrix?

Thanks in advance
Hung

My test code:

#include <iostream>
#include <fstream>
#include <string>

#include "Eigen/Dense"

using std::string;
using std::cout;
using std::endl;
using namespace Eigen;

template <class T>
inline Matrix<T, Dynamic, Dynamic> & func1(){
  // Do something then return a matrix
  Matrix<T, 3, 5> A;
  return A;
}

inline MatrixXd func2(){
  // Do something then return a matrix
  MatrixXd A(3,5);
  return A;
}

int main (int nargc, char *argv[]){
  string dataFileName = "dat.txt";

  Matrix<double, Dynamic, Dynamic> A = func1();
  cout << "Matrix A:" << endl << A << endl;

  // MatrixXd B = func2();
  // cout << "Matrix B:" << endl << B << endl;

  return 0;
}




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/