digitalmars.D.bugs - named union : needs 'this' to access member error
- David L. Davis (40/40) Jun 17 2005 # // needthis.d
- Derek Parnell (38/75) Jun 17 2005 Not a bug.
- Tom S (3/3) Jun 17 2005 Damn, Derek was faster ;)
- David L. Davis (9/46) Jun 17 2005 Thanks Derek...funny thing tho, this example is a part of some D code th...
- Tom S (16/51) Jun 17 2005 I believe it's intended to work this way... Make the union's name e.g.
- David L. Davis (9/60) Jun 17 2005 Thanks Tomasz!
- Tom S (4/6) Jun 18 2005 Not me, sorry ;) I enjoyed playing Heretic2 but I never made a map for i...
Output: ---------- C:\dmd>dmd needthis.d needthis.d(26): need 'this' to access member AsciiChar C:\dmd> David L. ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!" ------------------------------------------------------------------- MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html
Jun 17 2005
On Sat, 18 Jun 2005 02:24:55 +0000 (UTC), David L. Davis wrote:Output: ---------- C:\dmd>dmd needthis.d needthis.d(26): need 'this' to access member AsciiChar C:\dmd>Not a bug. If you name a union, then you must create an instance of it before you can reference its members. If you don't name a union, then the union becomes its own instance. struct CHAR_INFO { union { WCHAR UnicodeChar; CHAR AsciiChar; } } In this case, the anonymous union is also an instance of itself so you can reference its members directly. CHAR_INFO chiFill; chiFill.UnicodeChar = '\x20'; However ... struct CHAR_INFO { union Char { WCHAR UnicodeChar; CHAR AsciiChar; } Char aChar; } In this case, the union is named so you have to create an instance of it first, then reference member through that instance. CHAR_INFO chiFill; chiFill.aChar.UnicodeChar = '\x20'; If you use the union name itself in the reference, then you need to only reference 'static' members, and I'm not sure what that would be. -- Derek Melbourne, Australia 18/06/2005 12:46:21 PM
Jun 17 2005
Damn, Derek was faster ;) -- Tomasz Stachowiak /+ a.k.a. h3r3tic +/
Jun 17 2005
In article <trarz7rthih8.140fc8415dmrw$.dlg 40tude.net>, Derek Parnell says...Not a bug. If you name a union, then you must create an instance of it before you can reference its members. If you don't name a union, then the union becomes its own instance. struct CHAR_INFO { union { WCHAR UnicodeChar; CHAR AsciiChar; } } In this case, the anonymous union is also an instance of itself so you can reference its members directly. CHAR_INFO chiFill; chiFill.UnicodeChar = '\x20'; However ... struct CHAR_INFO { union Char { WCHAR UnicodeChar; CHAR AsciiChar; } Char aChar; } In this case, the union is named so you have to create an instance of it first, then reference member through that instance. CHAR_INFO chiFill; chiFill.aChar.UnicodeChar = '\x20'; If you use the union name itself in the reference, then you need to only reference 'static' members, and I'm not sure what that would be. -- Derek Melbourne, Australia 18/06/2005 12:46:21 PMThanks Derek...funny thing tho, this example is a part of some D code that compiled fine with D v0.97 in July 2004 ( somehow I missed retesting this code some 30 version of D ago :P ). Thanks again. David L. ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!" ------------------------------------------------------------------- MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html
Jun 17 2005
I believe it's intended to work this way... Make the union's name e.g. UChar and then declare it inside the struct, like: David L. Davis wrote:Output: ---------- C:\dmd>dmd needthis.d needthis.d(26): need 'this' to access member AsciiChar-- Tomasz Stachowiak /+ a.k.a. h3r3tic +/
Jun 17 2005
In article <d902fe$2gfd$1 digitaldaemon.com>, Tom S says...I believe it's intended to work this way... Make the union's name e.g. UChar and then declare it inside the struct, like: David L. Davis wrote:Thanks Tomasz! BTW, your handle / alias "h3r3tic" reminds me of someone that had a similar name, who I remember made good levels / maps for "Heretic 2" back in the day. David L. ------------------------------------------------------------------- "Dare to reach for the Stars...Dare to Dream, Build, and Achieve!" ------------------------------------------------------------------- MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.htmlOutput: ---------- C:\dmd>dmd needthis.d needthis.d(26): need 'this' to access member AsciiChar-- Tomasz Stachowiak /+ a.k.a. h3r3tic +/
Jun 17 2005
David L. Davis wrote:BTW, your handle / alias "h3r3tic" reminds me of someone that had a similar name, who I remember made good levels / maps for "Heretic 2" back in the day.Not me, sorry ;) I enjoyed playing Heretic2 but I never made a map for it -- Tomasz Stachowiak /+ a.k.a. h3r3tic +/
Jun 18 2005