Registered Member
|
I am hoping that somebody with more experience can tell me how I can declare an Eigen matrixXd as a private member and then resize the matrix in a function "resizeN()".
This fails to compile stating that "N" is private
But declaring the matrixXd as a public member appears to compile without any errors. Any suggestions, help, or clarification would be greatly appreciated. Resizing other STL vectors seems to be okay. |
Registered Member
|
This should work. Your code has some issues: MatrixXd is with capital M, the declaration for the member function resizeN does not take an argument but the definition does. After fixing those, it compiles here. For reference, this is the program I used:
|
Registered Member
|
Hi, there. I had met a similar problem.
#include "Eigen/Dense" #include <iostream> class InverseKinematics { private: static const int SoluNum=8; Eigen::MatrixXi signMatrix; public: InverseKinematics(); ~InverseKinematics(); public: void testFunc(); }; InverseKinematics::InverseKinematics () { Eigen::MatrixXi signMatrix(SoluNum,3); signMatrix<< 1, 1, 1, 1, 1,-1, 1,-1, 1, 1,-1,-1, -1, 1, 1, -1, 1,-1, -1,-1, 1, -1,-1,-1; } InverseKinematics::~InverseKinematics () { // } void InverseKinematics::testFunc () { std::cout<<"signMatrix=\n"<<signMatrix<<std::endl; } int main () { InverseKinematics InverObj; InverObj.testFunc(); system("PAUSE"); return 0; } /** I expected to display the private data member signMatrix(a 8*3 matrix), but the results showed nothing, and the pointer of signMatrix pointed at 0x00000000. I donnot know why, can anybody explain it, thanks. ***/ |
Moderator
|
In your constructor you create a local variable signMatrix that has the same name as your member. Therefore, InverseKinematics::signMatrix remains not initialized. Possible fix (you can also call resize in the ctor body):
|
Registered Member
|
I'd like to thank ggael a lot, and the problem had been solved, thanks.
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]