Aaaargh! noob question static string array initialization

A

anti-guru

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.

I've consulted my Deitel book, and my c++ primer, but I can't seem to put
the pieces together.

If it's not too much to ask, could you please not use any STL if you reply;
I'm barely treading water with the regular language.

Thanks!
 
J

John Harrison

anti-guru said:
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.

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top