Re: [eigen] How to return an Eigen matrix |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] How to return an Eigen matrix
- From: Hung Dang <hungptit@xxxxxxxxx>
- Date: Sat, 08 Oct 2011 23:17:37 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:reply-to:user-agent:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=+lqQe21xY63SxGNF0ySwVbEACx7L4NqyuoxXqCjEyxs=; b=ODhgP35zPo1kSAs86RMDXlrlGRaQOYFxiZG+JFwBDHbtOe3v0eCGpfTmRIw4vAeb3w BJLERY7lqyGrNBbWDNFeWkdAnKwoc6lCNpEkv5r0DTYdv+r7D6LQmvrbbQYUEFWJW0KO N4E8Ou8QoDCezTZ+EWsE9WqSI70mT33cZByvE=
Thanks a lot Jitse, Manuel, and Jose. I have resolved my problem using
your suggestions.
Hung
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
>
>