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

"Default Constructor Problem With Block"

Tags: None
(comma "," separated)
poqovic
Registered Member
Posts
9
Karma
0
OS
So there must be default constructor for Eigen::Block class. When i want to insert member Eigen::Block into a class with no initialization i get problem with it, do i have to initialize Eigen::Block before occupying memory for it. When i look size of Eigen::Block<MatrixXd> for example, it's size doesn't depent on row and col count and is only 20 byte. SO why i cant use it in a class? Do i have to define a pointer for it and allocate memory for it on containing class like this:

Code: Select all
class cl{
public:


private:
Eigen::Block<MatrixXd> p;



};


int main(){

cl myc;//No default constructor problem



}


do i have to use like this,

Code: Select all
class cl{
public:
cl(MatrixXd){
if(!p){
p=new Eigen::Block<MatrixXd>(MatrixXd,0,0,10,10);
}

}

private:
Eigen::Block<MatrixXd>* p;



};


int main(){
MatrixXd xd(10,10);
cl myc(xd);



}
poqovic
Registered Member
Posts
9
Karma
0
OS
any suggestions?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
A block object is not aimed to be change, so you have to bound it to a matrix at construction time. If you really want to change its target matrix, then you will have to the placement new C++ syntax (see the Map documentation for an example). So you could initialize your Block member object with a dummy matrix.


Bookmarks



Who is online

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