digitalmars.D - this() to access unions?
- Tyro <ridimz_at yahoo.dot.com> Nov 22 2004
- "Simon Buchan" <currently no.where> Nov 22 2004
- Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> Nov 22 2004
- Tyro <ridimz_at yahoo.dot.com> Nov 22 2004
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...
# union theValue_t {
# uint bits32;
# char[4] bytes;
# }
#
# theValue_t theValue;
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... # union theValue_t { # uint bits32; # char[4] bytes; # } # # theValue_t theValue; 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









"Simon Buchan" <currently no.where> 