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

Annoying warning compiling MatrixBase<Derived>::cross

Tags: None
(comma "," separated)
christopherbatty
Registered Member
Posts
8
Karma
0
OS
I'm compiling under Visual C++ 2008, and I get the warning message below when compiling the "cross" function. Is there a way to get rid of this (aside from disabling warnings)? eg. will it break things if I just removed the const qualifier?
Thanks!

1>c:\users\christopher batty\documents\libraries\eigen_3\eigen\src/Geometry/OrthoMethods.h(46) : warning C4181: qualifier applied to reference type; ignored
1> ..\..\..\BASim\src\Render\ShellRenderer.cpp(46) : see reference to function template instantiation 'Eigen::Matrix<_Scalar,_Rows,_Cols> Eigen::MatrixBase<Derived>::cross<Derived>(const Eigen::MatrixBase<Derived> &) const' being compiled
1> with
1> [
1> _Scalar=double,
1> _Rows=3,
1> _Cols=1,
1> Derived=Eigen::Matrix<double,3,1>
1> ]
1>c:\users\christopher batty\documents\libraries\eigen_3\eigen\src/Geometry/OrthoMethods.h(47) : warning C4181: qualifier applied to reference type; ignored
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
I've never seen this warning when compiling the unit tests, could you show the respective expression calling cross (with the type of the involved variables)? thanks
christopherbatty
Registered Member
Posts
8
Karma
0
OS
The line of code is:

Vec3d b = t1.cross(t2);

where Vec3d is a typedef for a 3x1 Eigen matrix:

typedef Eigen::Matrix<Scalar, 3, 1> Vec3d; ///< 3d scalar vector
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
hm, ok, strange we did not hit it yet.

So the warning comes from:

const typename internal::nested<Derived,2>::type lhs(derived());

where Derived is a Matrix, and then typename internal::nested<Derived,2>::type returns a "Matrix&", and I don't really see why it complains by the const...

Maybe, could you try to change the line 46 of Eigen/src/Geometry/OrthoMethods.h to:

Code: Select all
typename internal::nested<Derived,2>::type const lhs(derived());


i.e., move the "const" after the type and do the same for line 47.

thanks.
christopherbatty
Registered Member
Posts
8
Karma
0
OS
If I understand correctly, the issue is that applying the const qualifier to the typedef tries to make the reference itself const, not the object it refers to. In the same way that trying to declare:
int& const x;
doesn't actually work (or mean anything reasonable).

See eg.
http://stackoverflow.com/questions/3801 ... lates-in-c

Moving the qualifier to after the type doesn't seem to help, since it's still doing essentially the same thing.


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], q.ignora