Initializer for an array of pointers to arrays of strings

Discussion in 'C++' started by Steve, Jan 24, 2004.

  1. Steve

    Steve Guest

    I want an initializer for an array of pointers to arrays of strings.

    So I can do something like this:

    const char* t1[] = { "a", "b", "c", 0 };
    const char* t2[] = { "p", "q", 0 };
    const char* t3[] = { "w", "x", "y", "z", 0 };
    const char* const* test[] = { t1, t2, t3, 0 };

    I was wondering whether the is a more elegant way of writing such an
    initializer, one that does away with all the redundant names t1, t2, etc.

    Many thanks
    Steve
     
    Steve, Jan 24, 2004
    #1
    1. Advertising

  2. "Steve" <> wrote...
    >
    > I want an initializer for an array of pointers to arrays of strings.
    >
    > So I can do something like this:
    >
    > const char* t1[] = { "a", "b", "c", 0 };
    > const char* t2[] = { "p", "q", 0 };
    > const char* t3[] = { "w", "x", "y", "z", 0 };
    > const char* const* test[] = { t1, t2, t3, 0 };
    >
    > I was wondering whether the is a more elegant way of writing such an
    > initializer, one that does away with all the redundant names t1, t2, etc.


    Why do you say that they are redundant? If you want a pointer to
    an array, you gotta have the array first. The only way to have
    an array in C++ is to define one. That's what you need the tX for.
    There are no "array literals" in C++.

    V
     
    Victor Bazarov, Jan 25, 2004
    #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. kelvSYC

    Arrays and Pointers to Arrays

    kelvSYC, Sep 26, 2003, in forum: C Programming
    Replies:
    2
    Views:
    390
  2. Steve
    Replies:
    2
    Views:
    369
    Steve
    Jan 24, 2004
  3. Replies:
    1
    Views:
    663
    -berlin.de
    Mar 28, 2005
  4. Francesco
    Replies:
    2
    Views:
    1,127
    Francesco
    Nov 6, 2009
  5. cerr

    pointers, pointers, pointers...

    cerr, Apr 7, 2011, in forum: C Programming
    Replies:
    12
    Views:
    695
Loading...

Share This Page