Registered Member
|
Hi,
I would like to store and pass around a reference to a block expression, e.g.:
I have tried using the Eigen::Ref class but I ran into a problem, since there is no paramerless constructor in this class. Because of this, I can't declare the reference variable and assign the reference later. In my particular scenario, I used a std::map to store the refs:
which failed because the map tried to create an empty reference Eigen::Ref(). I have managed to fix it with a workaround using a pointer to Ref:
but this is a bit convoluted way of storing a reference to the block. Is there a better/proper way of doing this? |
Moderator
|
Eigen::Ref is supposed to behave as closely as possible to a c++ reference, like "double&". This is why there is no default ctor. If we were adding such a default ctor, then we would also need to add another method to modify a Ref such that it references another object. Indeed, Ref::operator= is supposed to modify the referenced object, not the Ref object itself.
Anyways, in your case, using std::map::insert instead of std::map::operator[] should do the job. |
Moderator
|
For the record, here is an example:
|
Moderator
|
Btw, we also plain to add Ptr<> analogue to C++ pointers. Ptr<> will be more friendly with std::map. See: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=912
|
Registered Member
|
Thanks.
This will work for now and the Ptr<> class seems like a great idea |
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]