On Jan 29, 12:10=A0am, "Jim Langston" <tazmas...@rocketmail.com> wrote:
DDD wrote:
I have some codes:
=A0 =A0 =A0 =A0w_char **sFieldsUri;
Okay, sFieldsUri is a pointer to a pointer to a w_char.
=A0 =A0 =A0 =A0sFieldsUri =3D &(new w_char[2]);
new returns a pointer to the allocated memory. =A0You are trying to get th=
e
address of this pointer? =A0wtf? =A0I 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 =3D new w_char*[2];
Now sFieldsUri would point to to w_char pointers. =A0Now you could allocat=
e
the acutal memory for the w_chars.
sFieldsUri[0] =3D new w_char[somesize];
sFieldsUri[1] =3D new w_char[somesize];
Allocating memory this way is fairly confusing and one can get lost as to
where their pointers actually point. =A0It is better to not use pointers i=
f
you can. =A0What is wrong with std::string?
=A0 =A0 =A0 =A0w_char **sValFind =3D nsnull;
=A0 =A0 =A0 =A0sValFind =3D =A0&(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:
=A0 =A0 =A0 =A0w_char **sFieldsUri;
=A0 =A0 =A0 =A0sFieldsUri =3D &(new w_char[2]);
=A0 =A0 =A0 =A0for(int i=3D0; i<2; i++)
=A0 =A0 =A0 =A0{
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0sFieldsUri[i] =3D new w_char[100];
=A0 =A0 =A0 =A0}
=A0 =A0 =A0 =A0w_char **sValFind =3D nsnull;
=A0 =A0 =A0 =A0sValFind =3D =A0&(new w_char[2]);
=A0 =A0 =A0 =A0for(int i=3D0; i<2; i++)
=A0 =A0 =A0 =A0{
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0sVal Find[i] =3D new w_char[100];
=A0 =A0 =A0 =A0}
sFieldsUri+0, =A0sFieldsUri+1, and sValFind+0, sValFind+1 are all
difference.
Thanks for all.
--
Jim Langston
tazmas...@rocketmail.com
Thank you very much, Jim. Yes, you are right. &(new w_char[2]) is not
I wanna get. And new w_char*[2] works well.
Last, I wanna say that &(new w_char[2]) works differently in debug and
release version, because sValFind =3D &(new w_char[2]) is a error, a
big error.
.