|
[quote=luceric;22885]your code is wrong. “name” is already a pointer, why do you take the address of it?
The correct way to use this is
char name[] = “xsi”;
CString myStr(name);
also wrong, there should be no & there
you may be confused by the C language. [B]name [/B]is of type [B]char *[/B]
[B]char name[] = “xsi”;[/B]
is equivalent to
[B]char *name = “xsi”;[/B]
(there is a technical storage difference, but it “name” is the same type in both case)
Uhh, did you actually try to run this code? Did it actually print out “xsi”? Try this with 7.5 SDK:
Application app = Application();
char hi[] = "xsi";
CString msg(hi);
app.LogMessage(msg);
And tell me what it prints out.
char [] (array) is certainly not the same type as char *. They are “equivalent” in the sense that functions accepting char * will take char [] because char arrays will *decay* into pointers when passed as parameters. But you certainly can’t assign like below.
char array[] = "v1"; char * pointer = "v2"; pointer = array; // ok, automatically converted array = pointer; // error, can't convert array type to pointer type
So in the first example I gave in the my first post what does &name give you? It’s a pointer to an array. I tried it because passing in the char [] array like CString str(name) did *not* work properly, printing out a number rather than the actual string. So I tried all kinds of variations to pass in this char*, none of them worked properly.
The SDK is bundled with XSI version 7.5.2009.0204.
|