|
-
April 7th, 2013, 06:10 AM
#3
Re: Can't intialize C++ Struct with CString in it??
 Originally Posted by ADSOFT
Code:
struct print
{
int x; //row
int y; //col
int fid;
CString *data;
char *format;
};
struct print form [] =
{
{ 30, 40, 1,"Name", "N/A" },
{ 30, 42, 1,"Address", "N/A" },
{ 30, 44, 1,"City State, Zipcode", "N/A" },
{ 30, 50, 1,"Vehicle", "N/A" },
};
The struct keyword is not necessary in C++ to define a variable of type 'print'.
What you are trying to do here is to convert a const char[] to a CString*. That's not possible, because these are unrelated types. A CString* must point to a CString. In your code you did not instantiate CString, so there is nothing to point to.
 Originally Posted by ADSOFT
tried CSting data and that also doesn't work,
If I compile that, I get an error like
Code:
error C2440: 'initializing' : cannot convert from 'const char [5]' to 'CString'
Constructor for class 'ATL::CStringT<BaseType,StringTraits>' is declared 'explicit'
That's pretty self-explanatory. The CString constructor that takes a const char* is declared explicit, so you cannot implicitly convert from a const char* to a CString. You need to explicitly create a CString in your initialization.
Code:
print form = { 30, 40, 1, CString("Name"), "N/A" };
Note that if you have a unicode build, you need to pass CString a const wchar_t*, which you can do by prefixing the string literal with L. I.e.
Code:
print form = { 30, 40, 1, CString(L"Name"), "N/A" };
If you need to support both unicode and MBCS builds, you can wrap the string literal with the _T() macro.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|