0
votes

I'm using the Eigen Library here: http://eigen.tuxfamily.org/index.php?title=Main_Page

When trying to compile this, it returns

error: expected constructor, destructor, or type conversion before '.'

complaining about the lines where i add the xaxis...zaxis to the matrix. is it possible it's because gcc4.3 (which is the compiler i'm using) doesn't like this type of initialization because the dot usually is a function call (which wouldn't work on an uninitialized object)?

but to me it seems to follow exactly the tutorial example here: http://eigen.tuxfamily.org/dox/TutorialAdvancedInitialization.html , except for the static, but the error is the same without it. I tried using the comma separated initialization but again it's the same.

// axis system
static Eigen::Matrix<double, 3, 1>    s_xAxis(1.,0.,0.);            //!< global x Axis;
static Eigen::Matrix<double, 3, 1>    s_yAxis(0.,1.,0.);            //!< global y Axis;
static Eigen::Matrix<double, 3, 1>    s_zAxis(0.,0.,1.);            //!< global z Axis;

// origin
static Eigen::Matrix<double, 3, 1>    s_origin(0.,0.,0.);           //!< origin position

static Eigen::Matrix<double, 3,3>     s_idRotationZinverse;
s_idRotationZinverse.col(0) << s_yAxis;
s_idRotationZinverse.col(1) << s_xAxis;
s_idRotationZinverse.col(2) << -s_zAxis;
2
Maybe it's just unfamiliarity but is 1. actually valid syntax (as opposed to 1.0)? The compiler complaint comes right where you would but the 0. - Matt Phillips
The syntax on the referenced page suggests you need: static Eigen::Matrix<double, 3, 1> s_xAxis; s_xAxis << 1., 0., 0.; using << to initialize the variable. - Jonathan Leffler
sorry, i forgot to specify the line. compliant comes at s_idRotationZinverse.col(0) so it's this dot - the_toast
The code you've posted is syntatically correct and doesn't cause problems on GCC 4.3, tried ideone.com/7ITDVK - Kos
@Kos i should have explicitly written i'm using the Eigen library. Thanks for trying it out like this, at least i know the compiler should accept this syntax. - the_toast

2 Answers

1
votes

Oh, I got this.

This code:

s_idRotationZinverse.col(0) << s_yAxis;

isn't a declaration; it's a statement that has to be inside a function body.

You're probably trying to execute it outside of any function, which is syntactically incorrect and causes the error you mentioned.

You might have been tricked by the Eigen documentation, which calls this syntax "comma initialization" where it should be "comma assignment" or so. Initialization is when you give the variable a value when it's defined, not as a separate step. Initialization is syntactically a part of the declaration, so it can be done outside of function bodies.

I suggest to fork Eigen to support the new std::initializer_list-based initialization (if it's not done yet) and submit a pull request.

0
votes

Have you tried:

s_idRotationZinverse.col(0) = s_yAxis;