 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Rob Guest
|
Posted: Sun Mar 07, 2004 9:51 pm Post subject: Trouble understanding pointer to a const array. |
|
|
Hi,
I receive the following compile error.
c:..Blah.cpp(52) : error C2440: 'initializing' : cannot convert from
'const char *const [64]' to 'char ** '
Conversion loses qualifiers
< outside of main>
enum { sz = 64};
const char* const names[sz] =
{ "Frodo", "Gollum", "Sam", "Treebeard",
"King", "Garcia", "Burdine",
"Eriksen", NULL };
<within main>
<line 52> for (char** p = names; *p; p++)
{;}
I thought names was a pointer to an array of string literals, whose
values could not be change, nor could the location where names pointed
to be changed.
With char** p, I'm trying to point to where names points to. Please
explain where I've gone wrong.
Thanks,
Rob
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Sun Mar 07, 2004 10:35 pm Post subject: Re: Trouble understanding pointer to a const array. |
|
|
"Rob" <robpimentel (AT) yahoo (DOT) com> wrote...
| Quote: | I receive the following compile error.
c:..Blah.cpp(52) : error C2440: 'initializing' : cannot convert from
'const char *const [64]' to 'char ** '
Conversion loses qualifiers
outside of main
enum { sz = 64};
const char* const names[sz] =
|
If you have your "list" of names always end with a null pointer, why
have the size at all?
| Quote: | { "Frodo", "Gollum", "Sam", "Treebeard",
"King", "Garcia", "Burdine",
"Eriksen", NULL };
within main
line 52> for (char** p = names; *p; p++)
|
If you need to iterate over the array of const char*, you have to
declare your 'p' as const char**.
| Quote: | {;}
I thought names was a pointer to an array of string literals, whose
values could not be change, nor could the location where names pointed
to be changed.
With char** p, I'm trying to point to where names points to. Please
explain where I've gone wrong.
|
One more thing you've done wrong is not posting the _entire_ code.
Consider visiting the FAQ section 5 at some point in the future.
Victor
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|