Array of string arrays

Hi,

I need to define an array of (c)string arrays as a static class member. I tried the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//MyClass.h

typedef const char * LPCChar
class MyClass
{
 static const LPCChar sarr[][3]
};

//MyClass.cpp

const MyClass::LPCChar sarr[][3] = {
 {
  {
   "Hannah",
   "Peter"
  },
  {
   "Fish"
  },
  {
   "One",
   "Two",
   "Three"
  }
 }
}

This works but as soon as I define such an array containing at least one (sub-)array consisting of 18 or more strings I get (in VC++ 2010) the compiler error C2078 ("too many initializers").

Is there any other way of defining an array of string arrays (in ISO C++ & standard [template] libs) or to avoid that error?
the three as the second parameter in the declaration of sarr[][3] means that each subarray can have at most three strings, so if you try for example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const MyClass::LPCChar sarr[][3] = 
{
   {
      "Hannah",
      "Peter"
   },
   {
      "Fish"
   },
   {
      "One",
      "Two",
      "Three",
      "Four"
   }
};


This will cause it to fail. you be able to have as many blocks of strings as you like since you did not specify a maximum number as the first parameter.
Oh, so I just confused the order of brackets. What a silly mistake...

Many thanks, this would have never come to my mind!!!
Topic archived. No new replies allowed.