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

Declare MatrixXd as private member

Tags: None
(comma "," separated)
seanl
Registered Member
Posts
6
Karma
0

Declare MatrixXd as private member

Wed Sep 04, 2013 2:05 pm
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

Code: Select all
#include "Eigen/Eigenvalues"

class Foo {
     private:
          Eigen::matrixXd N;

     public:
          void resizeN();
};


Code: Select all
void Foo::resizeN (int t){
     N.resize(t, t);
}


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.
jitseniesen
Registered Member
Posts
204
Karma
2
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:
Code: Select all
#include "Eigen/Eigenvalues"

class Foo {
     private:
          Eigen::MatrixXd N;

     public:
          void resizeN(int t);
};

void Foo::resizeN (int t){
     N.resize(t, t);
}

int main (){
  Foo tmp;
  tmp.resizeN(10);
}
doogoofeng
Registered Member
Posts
2
Karma
0
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. ***/
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
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):
Code: Select all
InverseKinematics::InverseKinematics() : signMatrix(SoluNum,3)
{
 ...
}
doogoofeng
Registered Member
Posts
2
Karma
0
I'd like to thank ggael a lot, and the problem had been solved, thanks.


Bookmarks



Who is online

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