Registered Member
|
Hello,
I'd like to write code that allows access to a block of a matrix for use as an lvalue or rvalue through a function call. Something along the lines of class BigVec { public: Vector4d vec; Vector2d & LittleVec() { return vec.block<2,1>(0,0); } }; int main(int argc, char ** argv) { BigVec bv; bv.LittleVec() = Vector2d::Ones(); cout << bv.LittleVec(); } When compiling I get: "invalid initialization of non-const reference of type ‘Eigen::Vector2d&’ from an rvalue of type Eigen::Block<Eigen::Matrix<double, 4, 1>, 2, 1, false, true>’" A potentially related issue: http://listengine.tuxfamily.org/lists.t ... 00145.html It seems like the solution is in getting the return type of the function right, but I'm not sure what that would be. Thanks, Adam |
Moderator
|
have a look at Eigen/src/Geometry/Transform.h file to see such examples. Search for linear() and translation().
|
Registered Member
|
Thanks for the help!
By making the return type Block (not as a reference) the code works. class BigVec { public: Vector4d vec; Block<Vector4d, 2, 1> LittleVec() { return vec.block<2, 1>(0, 0); } }; |
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]