|
-
April 9th, 2013, 06:33 AM
#15
Re: Can't intialize C++ Struct with CString in it??
 Originally Posted by Igor Vartanov
Sure it didn't. Why does your structure has two members named data? Why you initialization list entries differ in passed types?
Tried the following and it worked just fine.
Code:
#include <windows.h>
#include <atlstr.h>
#define COUNTOF(x) (sizeof(x)/sizeof(x[0]))
struct print
{
int x; //row
int y; //col
int fid;
CString sData;
char *chData;
};
CString temp("Address");
struct print form [] =
{
{ 30, 40, 1,CString("Name"), "N/A" },
{ 30, 42, 1, temp , "N/A" },
{ 30, 44, 1, temp, "N/A" },
{ 30, 50, 1, temp, "N/A" },
};
int main()
{
for (int idx = 0; idx < COUNTOF(form); idx++)
{
printf(TEXT("[%d] x:%d y:%d sData:%s chData:%s\n"),
idx, form[idx].x, form[idx].y, form[idx].sData, form[idx].chData);
}
return 0;
}
Code:
E:\Temp\679>cl 679.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
679.cpp
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.
/out:679.exe
679.obj
Code:
E:\Temp\679>679
[0] x:30 y:40 sData:Name chData:N/A
[1] x:30 y:42 sData:Address chData:N/A
[2] x:30 y:44 sData:Address chData:N/A
[3] x:30 y:50 sData:Address chData:N/A
thanks for that example,
I copied the area where you defined the vars and struct, still won't compile. Maybe it's the compiler these guys are using?
V6.0, lol.
I will have to ask them if they want to upgrade.
I'm going to try your program in a CONSOLE app see what happens. If you have a V6.0 compiler handy try your program in it, I'm curious now.
btw I understand about the temp("data"), thing, I was just trying as many CString constructor variations.
Rate this post if it helped you.
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
|