Re: [eigen] How to return an Eigen matrix

[ Thread Index | Date Index | More Archives ]

Thanks a lot Jitse, Manuel, and Jose. I have resolved my problem using
your suggestions.


On 10/01/11 10:03, Jitse Niesen wrote:
> On Sat, 1 Oct 2011, Hung Dang wrote:
>> 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.
>> [...]
>> template <class T>
>> inline Matrix<T, Dynamic, Dynamic> & func1(){
>>  // Do something then return a matrix
>>  Matrix<T, 3, 5> A;
>>  return A;
>> }
>> [...]
>>  Matrix<double, Dynamic, Dynamic> A = func1();
> In addition to the issues pointed out by Jose and Manuel, there is
> also the problem that the different instantiations of func1 only
> differ in the return type. When you write "func1()", the compiler does
> not know whether you want the template argument T to be double or int
> or something else (in principle it could derive it from the context in
> this case, but the C++ standard says it shouldn't). Thus, you have to
> specify that T is double by writing
>    Matrix<double,Dynamic,Dynamic> A = func1<double>();
> A book on C++ template should point you in the right direction.
> Jitse

Mail converted by MHonArc 2.6.19+