Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Aaaargh! noob question static string array initialization

Reply
Thread Tools

Aaaargh! noob question static string array initialization

 
 
anti-guru
Guest
Posts: n/a
 
      09-01-2004
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!


 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      09-01-2004

"anti-guru" <(E-Mail Removed)> wrote in message
news:iJrZc.71955$(E-Mail Removed).. .
> 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


 
Reply With Quote
 
 
 
 
anti-guru
Guest
Posts: n/a
 
      09-02-2004
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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
initialization of array as a member using the initialization list aaragon C++ 2 11-02-2008 04:57 PM
Noob question: why the confusing syntax (data typevariable_name(value)) for initialization krishna C++ 6 09-24-2008 08:58 AM
Here a noob, there a noob.... JimDoire MCSE 0 04-10-2008 07:23 PM
static (non-zero) initialization of an array of structs (array of length #define LEN) anon.asdf@gmail.com C Programming 23 08-28-2007 11:54 PM
array initialization in initialization list. toton C++ 5 09-28-2006 05:13 PM



Advertisments