Eigen Matrix cannot be passed by reference: lvalue reference to tvalue error

Viewed 241

my class Batman has the following function:

void doFoo(Eigen::Matrix<int, Eigen::Dynamic, 1> &results){
  ...
}

And I am trying to call the function like this:

const int dim=3
Eigen::Matrix<int, dim, 1> results;
indices.resize(dim,1);

Batman bat();
bat.doFoo(results);

But I am getting the following Error:

cannot bind non-const lvalue reference of type ‘Eigen::Matrix<int, -1, 1>&’ to an rvalue of type ‘Eigen::Matrix<int, -1, 1>’

Why?? The types should be the same? And what is the right way to do it?

EDIT Thanks to the comment I found out that the const int was the problem here, using int works.

Before that I looked a little bit into openSource Software and noticed that most use some templates like this:

        template <typename WrongMatrixType>
    static NearestNeighbourSearch* createKDTreeLinearHeap(const WrongMatrixType& cloud, const Index dim = std::numeric_limits<Index>::max(), const unsigned creationOptionFlags = 0, const Parameters& additionalParameters = Parameters())
0 Answers
Related