Re: More a C++ Q then vs... but why not?
From: Alf P. Steinbach (alfps_at_start.no)
Date: 07/07/04
- Next message: Clic King: "Re: VS6 with SP6 - debugging doubles and floats"
- Previous message: andrew: "Re: More a C++ Q then vs... but why not?"
- In reply to: Dead RAM: "More a C++ Q then vs... but why not?"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 07 Jul 2004 21:38:13 GMT
* Dead RAM:
> Well... Don't know C++ as well as a pro... so here goes...
>
>
> I want to do somthing like this:
>
> -------------------------------------------------------------------
> class someThing {
> public:
> // stuff, constructor, destructor, etc...
>
> private:
> const char myConstCharArrayInitializedAtObjectCreation[] =
> "blah";
> };
You can't have an array of indeterminate size as a member.
> --------------------------------------------------------------------
>
> After brute forcing my way through the errors I ended up with this:
>
>
> -------------------------------------------------------------------
> class someThing {
> public:
> // stuff, constructor, destructor, etc...
>
> private:
> const char* myConstCharArrayInitializedAtObjectCreation;
> };
>
> // more stuff
>
> someThing::someThing()
> : myConstCharArrayInitializedAtObjectCreation("blah")
> {
> // more stuff
> }
This is OK.
> -------------------------------------------------------------------
>
> I'm mainly wondering, in the second (and error free) version, is it the
> equivalent of the C statement:
>
> const char ch[]="blah"
No it isn't. What you have in class someThing is a pointer. What
you have right above is a character array.
> Umm... in other words, where is the "blah" data being stored
The "blah" has static storage.
The pointer to "blah" is being stored in your object.
One per object.
> and setup
?
> And am I running into a situation were the const char wasn't
> initialized properly and could potentialy lose the "blah" data
Not in the code presented here.
> (is the
> memory pointed to by the const char* valid, or does it just happend to work
> sometimes)?
In the code presented it is valid.
-- A: Because it messes up the order in which people normally read text. Q: Why is it such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail?
- Next message: Clic King: "Re: VS6 with SP6 - debugging doubles and floats"
- Previous message: andrew: "Re: More a C++ Q then vs... but why not?"
- In reply to: Dead RAM: "More a C++ Q then vs... but why not?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|