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

how to allocated a random matrix and return it in function?

Tags: None
(comma "," separated)
abdols
Registered Member
Posts
2
Karma
0
Hi everyone,
I'm not good in c++ and I need some help on this.
I have a function let's say Foo like:
Code: Select all
MatrixXd* Foo(dim1, dim2)
{
MatrixXd* X = new MatrixXd::Random(dim1, dim2);
return X;
}

This function doesn't work and gives me error. How can I return such a thing?
Thank you so much.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
MatrixXd::Random is a function, not a MatrixXd! You first need to allocate and then assign:
Code: Select all
MatrixXd* X = new MatrixXd(dim1, dim2);
X->setRandom();
abdols
Registered Member
Posts
2
Karma
0
Thanks for the quick reply.


Bookmarks



Who is online

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