Jeff said:
This doesn't compile:
const char** ids =
{
"aaa",
"bbb",
"ccc"
};
I hope the above illustrates what I am trying to do, if it is possible, what
is the correct syntax?
btw i want to create a static array where each element is a c-style array
(in case my example was unclear)
Your description of what you want doesn't match the solution you accepted.
const char *ids[] = { "aaa", "bbb", "ccc" };
This does not create an "array where each element is a c-style array."
(By the way, there's no "C++-style arrays", so you don't need to specify
C-style for an array. All arrays are C-style.) It creates an array where
each element is a pointer to a null-terminated character string. To get
what you described, you need something like this:
char ids[][N] = { "aaa", "bbb", "ccc" };
Where N is chosen to be large enough for your longest string (including
the null character).
As for making it static, it might depend on what exactly you mean by
that. Generally you just add the keyword 'static':
static char ids[][N] = { "aaa", "bbb", "ccc" };
But this has different meanings in different contexts, and the meaning
may not be the one you want.
If you meant "statically allocated" and the declaration is at namespace
or global scope, then you shouldn't need the 'static' at all. If the
declaration is in a function, you should add the 'static' keyword. If
the declaration is in a class, you need the 'static' and you also need a
separate definition outside the class, and you should move the
initializer to that definition.
-Kevin