need 'this' to access data member

clayasaurus clayasaurus at gmail.com
Tue Sep 26 20:50:14 PDT 2006


Chris Nicholson-Sauls wrote:
> 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.
>>
>> ~ Clay
>>
>>
>> ------------------------------------------------------------------------
>>
>> // 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 hide
>>     {
>>         version(Windows)
>>         {
>>             struct win32io
>>             {
>>                 int append;
>>                 void *h;
>>             }
>>         }
>>         struct stdio
>>         {
>>             int autoclose;
>>             FILE *fp;
>>         }
>>         struct mem
>>         {
>>             Uint8 *base;
>>             Uint8 *here;
>>             Uint8 *stop;
>>         }
>>         struct unknown
>>         {
>>             void *data1;
>>         }
>>     }
>>     hide hidden;     
>> }
>>
>>
>> int main()
>> {
>>     SDL_RWops w;
>>     // need 'this' to access data member data1??
>>     w.hidden.unknown.data1 = null;
>>     return 0; }
> 
> Because 'SDL_RWops.hidden.unknown' is a struct type decleration, not a 
> field decleration.  In the same way that you had to create a field of 
> type 'hide' in order to access its components ('hidden') you also need a 
> field of type 'unknown' to do so.
> 
> -- Chris Nicholson-Sauls

Thanks.
~ Clay



More information about the Digitalmars-d-learn mailing list