syntactic sugar for initializaing multidimentional arrays?

A

aaronfude

Hi,

Sorry to ask this question in such a backward way, but in java it is
possible to say

int[][] arr = new int[][] { { 1 }, { 1, 2}, { 1, 2, 3}};

Is it possible to do the same in C++ with an (int **)? (Understanding,
of course, that I will need to know the sizes of arrays when using
arr.)

Thanks,

Aaron Fude
 
V

Victor Bazarov

Sorry to ask this question in such a backward way, but in java it is
possible to say

int[][] arr = new int[][] { { 1 }, { 1, 2}, { 1, 2, 3}};

Is it possible to do the same in C++ with an (int **)? (Understanding,
of course, that I will need to know the sizes of arrays when using
arr.)

In C++ I'd recommend using std::vector :

std::vector<std::vector<int> > arr;

Although, initialisation of it is not a simple thing, especially since
its elements have different sizes.

V
 

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,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top