By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,955 Members | 1,275 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,955 IT Pros & Developers. It's quick & easy.

Aaaargh! noob question static string array initialization

P: n/a
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!
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"anti-guru" <me@none.com> wrote in message
news:iJ******************@bignews3.bellsouth.net.. .
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
Jul 22 '05 #2

P: n/a
Thank you! :)

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

Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.