DDD wrote:
I have some codes:
w_char **sFieldsUri;
Okay, sFieldsUri is a pointer to a pointer to a w_char.
sFieldsUri = &(new w_char[2]);
new returns a pointer to the allocated memory. You are trying to get the
address of this pointer? wtf? I don't think this is what you really want
to do.
Now, if you wanted your sFieldsUri to pointer two two arrays of w_char,
first you need to allocate memory for the pointers themselves.
sFieldsUri = new w_char*[2];
Now sFieldsUri would point to to w_char pointers. Now you could allocate
the acutal memory for the w_chars.
sFieldsUri[0] = new w_char[somesize];
sFieldsUri[1] = new w_char[somesize];
Allocating memory this way is fairly confusing and one can get lost as to
where their pointers actually point. It is better to not use pointers if
you can. What is wrong with std::string?
w_char **sValFind = nsnull;
sValFind = &(new w_char[2]);
When I debug my program, I found the above code had some strange
things. sFieldsUri+1 is equal to sValFind+0.
But if I change the codes to the following:
w_char **sFieldsUri;
sFieldsUri = &(new w_char[2]);
for(int i=0; i<2; i++)
{
sFieldsUri[i] = new w_char[100];
}
w_char **sValFind = nsnull;
sValFind = &(new w_char[2]);
for(int i=0; i<2; i++)
{
sVal Find[i] = new w_char[100];
}
sFieldsUri+0, sFieldsUri+1, and sValFind+0, sValFind+1 are all
difference.
Thanks for all.
--
Jim Langston
ta*******@rocketmail.com