Re: [eigen] Ref<> Problem |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Ref<> Problem
- From: Gabriel <gnuetzi@xxxxxxxxx>
- Date: Thu, 04 Dec 2014 09:58:56 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=Yy4EwqRaTMoWW6V71A12q94Nc/WfEP2G8Xn8+qLSFDQ=; b=obsee1tcck95H3CPxethvWQQCpR+J5CgJyq89oi4kvZd+DL56aHplR9EGahKF96Udg EA1qb/uUk6PfHst5THulK0q33Kk4djRbku3w9XuRtU4dQ8azkAhMdaejMO9wr4czvE5h W7JVCr0r+3Y6LcMTQBpSMyQH94C03ErchSdJWpIk+tjavpcl/zD64yO8m3X7noDi4qYz HMhmtZQ93utCXfb9aBz1iYYl5q/ufS7LQDnYnrK8+EBTRBtIBVWPwu9c1j0oZogyUNB0 +xlbvSqJy7pBJQhdlVQhdW1rZhzMA1s0+Uv5uOJ43dXy1ZMyFte1zj6vE6eqy0XcEWa/ Urwg==
Thanks a lot Christoph,
So what kind of strange things might happen:
So with your code, a temporary might be cosntructed by initializing r,
but because it is generated in the classes scope it is bound to exist
till struct A destructs?
If we assign elements of type A lets say
A a1;
A a2;
a1 = a2,
MIght be a problem , why? a1 copied the reference, right? it is still
valid , but if a2 internally stored a temporary than a1 refers to a
temporary in a2 which might blow up somewhen ?
Is that the problem?
Thanks a lot!
On 12/04/2014 01:11 AM, Christoph Hertzberg wrote:
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