need 'this' to access data member
Derek Parnell
derek at nomail.afraid.org
Tue Sep 26 22:26:07 PDT 2006
On Tue, 26 Sep 2006 22:22:05 -0500, clayasaurus wrote:
> Hi, I have the following code attached, and I do not understand why I
> can not access this data member. Help is very much appreciated, thanks.
As explained already, a named union/struct must also have a data
declaration before you can refer to its members. However, have you
considered anonymous union/struct ? When you use these, you can refer to
the members without having to qualify their names.
import std.stdio;
// datafield hacks
alias int FILE;
alias int Uint8;
// structure
struct SDL_RWops
{
int (*seek)(SDL_RWops *context, int offset, int whence);
int (*read)(SDL_RWops *context, void *ptr, int size, int maxnum);
int (*write)(SDL_RWops *context, void *ptr, int size, int num);
int (*close)(SDL_RWops *context);
uint type;
union
{
version(Windows)
{
struct
{
int append;
void *h;
}
}
struct
{
int autoclose;
FILE *fp;
}
struct
{
Uint8 *base;
Uint8 *here;
Uint8 *stop;
}
struct
{
void *data1;
}
}
}
int main()
{
SDL_RWops w;
// need 'this' to access data member data1??
std.stdio.writefln("autoclose A:" , w.autoclose);
w.data1 = &w; // sample data
std.stdio.writefln("autoclose B:" , w.autoclose);
version(Windows)
{
w.append = 42; // sample data
std.stdio.writefln("autoclose B:" , w.autoclose);
}
return 0;
}
--
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocrity!"
27/09/2006 3:22:49 PM
More information about the Digitalmars-d-learn
mailing list