Re: [eigen] Ref<> Problem |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
On 04.12.2014 00:14, Gabriel wrote:
How can I avoid such errors, and whats the correct way of storing a
reference to a Matrix in a class?
You must avoid that a temporary is constructed which runs out of scope
after being assigned to r:
struct A{
// constructor does not generate a temporary:
template<class Derived>
A(const Eigen::MatrixBase<Derived> & in) : r(in) {}
// initializing r might create a temporary but that is stored in r
Eigen::Ref<const Eigen::MatrixXd> r;
};
Be aware that strange things might happen, when you try to copy-assign
elements of type A.
Christoph
--
----------------------------------------------
Dipl.-Inf., Dipl.-Math. Christoph Hertzberg
Cartesium 0.049
Universität Bremen
Enrique-Schmidt-Straße 5
28359 Bremen
Tel: +49 (421) 218-64252
----------------------------------------------