This forum has been archived. All content is frozen. Please use KDE Discuss instead.

block reference return

Tags: None
(comma "," separated)
adampbry
Registered Member
Posts
2
Karma
0

block reference return

Sat Sep 10, 2011 3:08 am
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
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: block reference return

Sat Sep 10, 2011 7:23 am
have a look at Eigen/src/Geometry/Transform.h file to see such examples. Search for linear() and translation().
adampbry
Registered Member
Posts
2
Karma
0

Re: block reference return

Sat Sep 10, 2011 2:11 pm
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);
}

};


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]