Dynamic array and table?

S

saneman

std::vector<int> v creates a dynamic array where its possible to insert new
elements without doing any preallocation. But how about a dynamic double
array? I would like to have something like:


int M[a];

where a and b change be set during runtime and the size og M can vary, is
that possible?
 
M

mlimber

std::vector<int> v creates a dynamic array where its possible to insert new
elements without doing any preallocation. But how about a dynamic double
array? I would like to have something like:

int M[a];

where a and b change be set during runtime and the size og M can vary, is
that possible?


Try:

std::vector< std::vector<int> > M;

Depending on your application, there may be better ways to do it. See
also this FAQ and following:

http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.17

Cheers! --M
 
S

saneman

Victor Bazarov said:
saneman said:
std::vector<int> v creates a dynamic array where its possible to insert
new elements without doing any preallocation. But how about a dynamic
double array? I would like to have something like:


int M[a];

where a and b change be set during runtime and the size og M can vary, is
that possible?


It's not exactly equivalent, but you could try to get away with

std::vector<std::vector<int> > M(a, std::vector<int>(b));

V



Seems that boots:ublas has some dynamic vectors and matrices that I can use.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top