digitalmars.D - this() to access unions?
- Tyro (20/20) Nov 22 2004 The code below spews out the error "need 'this' to access member" ...
- Simon Buchan (9/29) Nov 22 2004 You only made a union type. You need to declare an instance like
- Thomas Kuehne (9/29) Nov 22 2004 You defined the type "theValue" but there is no var of this type...
- Tyro (3/42) Nov 22 2004 Duh! Can't believe I missed that. Thanks guys.
The code below spews out the error "need 'this' to access member" ... each time a member of theValue is accessed. I'm thoroughly confused. Please explain. Andrew =====endian.d===== import std.stdio; union theValue { uint bits32; char[4] bytes; } int main() { theValue.bytes[0]=0; theValue.bytes[1]=1; theValue.bytes[2]=0; theValue.bytes[3]=0; if(theValue.bits32==256) writefln("LittleEndian"); return 0; }
Nov 22 2004
On Mon, 22 Nov 2004 05:47:09 -0500, Tyro <ridimz_at yahoo.dot.com> wrote:The code below spews out the error "need 'this' to access member" ... each time a member of theValue is accessed. I'm thoroughly confused. Please explain. Andrew =====endian.d===== import std.stdio; union theValue { uint bits32; char[4] bytes; } int main() { theValue.bytes[0]=0; theValue.bytes[1]=1; theValue.bytes[2]=0; theValue.bytes[3]=0; if(theValue.bits32==256) writefln("LittleEndian"); return 0; }You only made a union type. You need to declare an instance like theValue aValue; pretty much anywhere. Unfortunately D doesnt allow the old <class type> [tag] {<class body>} [value list]; Which saved some keystrokes (Why cant I make an instance of a custom, one-off struct, Walter?) -- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 22 2004
You defined the type "theValue" but there is no var of this type... Thomas Tyro schrieb am Mon, 22 Nov 2004 05:47:09 -0500:The code below spews out the error "need 'this' to access member" ... each time a member of theValue is accessed. I'm thoroughly confused. Please explain. Andrew =====endian.d===== import std.stdio; union theValue { uint bits32; char[4] bytes; } int main() { theValue.bytes[0]=0; theValue.bytes[1]=1; theValue.bytes[2]=0; theValue.bytes[3]=0; if(theValue.bits32==256) writefln("LittleEndian"); return 0; }
Nov 22 2004
Duh! Can't believe I missed that. Thanks guys. Andrew Thomas Kuehne wrote:You defined the type "theValue" but there is no var of this type... Thomas Tyro schrieb am Mon, 22 Nov 2004 05:47:09 -0500:The code below spews out the error "need 'this' to access member" ... each time a member of theValue is accessed. I'm thoroughly confused. Please explain. Andrew =====endian.d===== import std.stdio; union theValue { uint bits32; char[4] bytes; } int main() { theValue.bytes[0]=0; theValue.bytes[1]=1; theValue.bytes[2]=0; theValue.bytes[3]=0; if(theValue.bits32==256) writefln("LittleEndian"); return 0; }
Nov 22 2004