syntactic sugar for initializaing multidimentional arrays?

Discussion in 'C++' started by aaronfude@gmail.com, Jan 24, 2005.

  1. Guest

    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
    , Jan 24, 2005
    #1
    1. Advertising

  2. wrote:
    > 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
    Victor Bazarov, Jan 24, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jason Heyes

    Is -> syntactic sugar?

    Jason Heyes, Dec 15, 2003, in forum: C++
    Replies:
    17
    Views:
    572
    Ron Natalie
    Dec 19, 2003
  2. Christopher T King

    xrange() syntactic sugar

    Christopher T King, Jan 9, 2004, in forum: Python
    Replies:
    0
    Views:
    312
    Christopher T King
    Jan 9, 2004
  3. F Jamitzky

    Ruby like syntactic sugar

    F Jamitzky, Mar 2, 2004, in forum: Python
    Replies:
    6
    Views:
    346
    Raymond Hettinger
    Mar 4, 2004
  4. Bas
    Replies:
    4
    Views:
    292
    Diez B. Roggisch
    Apr 14, 2006
  5. glomde
    Replies:
    34
    Views:
    740
    bruno at modulix
    May 19, 2006
Loading...

Share This Page