accessing union inside struct
-
Hi all I have the following scenario typedef struct _STRRET{ UINT uType; union { LPWSTR pol; UINT uof; char cStr[MAX_PATH]; }DUMMYUNIONNAME; }STRRET , *LPSTRRET; The problem is when i make a variable of type STRRET i couldn't acces the union variables. The following line include the code i wrote STRRET dispName; LPWSTR temp; temp = dispName.DUMMYUNIONNAME.pol; The compiler gives me compiling error: C2059 syntax error: '.' see declaration of _STRRET (which i know very good) Note: the above struct is a MFC defined type and don't know were is the problem may i have accessing the union in a wrong way or something. Sorry for my very stupid question and thanks for ur time in advance. Together we are stronger. I am so :wtf::((:confused::zzz: M.A.S.A
-
Hi all I have the following scenario typedef struct _STRRET{ UINT uType; union { LPWSTR pol; UINT uof; char cStr[MAX_PATH]; }DUMMYUNIONNAME; }STRRET , *LPSTRRET; The problem is when i make a variable of type STRRET i couldn't acces the union variables. The following line include the code i wrote STRRET dispName; LPWSTR temp; temp = dispName.DUMMYUNIONNAME.pol; The compiler gives me compiling error: C2059 syntax error: '.' see declaration of _STRRET (which i know very good) Note: the above struct is a MFC defined type and don't know were is the problem may i have accessing the union in a wrong way or something. Sorry for my very stupid question and thanks for ur time in advance. Together we are stronger. I am so :wtf::((:confused::zzz: M.A.S.A
-
I am sorry _Theo_ i don't understand u. The union name is defined in the MFC and i have no authority to midify it. So I must use the "DUMMYUNIONNAME " union name. Plllllllllllssssssssssss If u know any way of solving this problem i will be very greatful if u send it to me. Thank u Any way for ur quick reply and waiting for ur reply. I really want a solution for this problem. M.A.S.A
-
I am sorry _Theo_ i don't understand u. The union name is defined in the MFC and i have no authority to midify it. So I must use the "DUMMYUNIONNAME " union name. Plllllllllllssssssssssss If u know any way of solving this problem i will be very greatful if u send it to me. Thank u Any way for ur quick reply and waiting for ur reply. I really want a solution for this problem. M.A.S.A
-
Sorry I didn't realise it's a predefined structure. Leaving DUMMYUNIONNAME seems to work, so instead of using it call the union attributes right away like:
//temp = dispName.DUMMYUNIONNAME.pol; temp = dispName.pol;
_Theo_ thank u veeeeeeeeeeeeeeeeeeeeryyyyyyyyyyyy muchhhhhhhhhhhhhhhhhhhhhhh I don't know how to thank u for ur advice. U will not belive me that i have tried it before and it didn't work but after reading ur message i tried it again but this time it works. This job will make me made especially this stupid mistakes. Thank u again.
-
_Theo_ thank u veeeeeeeeeeeeeeeeeeeeryyyyyyyyyyyy muchhhhhhhhhhhhhhhhhhhhhhh I don't know how to thank u for ur advice. U will not belive me that i have tried it before and it didn't work but after reading ur message i tried it again but this time it works. This job will make me made especially this stupid mistakes. Thank u again.
Just to clarify why this works: Microsoft uses a #define for DUMMYUNIONNAME so that the same include file can be used with compilers that don't support unnamed unions. When you compile using Visual C++, the DUMMYUNIONNAME is #defined to a blank string, so the union doesn't have a name (and its members can be accessed directly). When you compile on a compiler which doesn't support unnamed unions, it is #defined to u (and you would need to include the .u before the member name).