| re: Aaaargh! noob question static string array initialization
"anti-guru" <me@none.com> wrote in message
news:iJrZc.71955$_h.67226@bignews3.bellsouth.net.. .[color=blue]
> This is killing me. How can I make a static array of two strings in my
> class?
>
> Nothing I've tried works. Here is what I currently have, which also
> doesn't
> work, but gives the least amount of compiler errors:
>
> in my header file:
>
> private:
> static char *stringTable[ 2 ];
>
> in my class source file:
>
> *stringTable[ 0 ] = new char[ strlen( "myString" )];
>
> This particular attempt says "cannot convert from 'char *' to 'char'
>
> Ideally, I would like to use curly brackets to initialize everything at
> once. I've tried to do that in the header, but I've learned that it
> doesn't
> allow that.
>[/color]
Assuming your class is called MyClass.
char* MyClass::stringTable[2] = { "mystring1", "myString2" };
Apart from the notation MyClass::stringTable this is exactly the same as the
initialisation of any static array.
john |