Welcome to Web-News
A Web-based News Reader
Subject Re: Introspection
From BCS <ao@pathlink.com>
Date Tue, 23 Sep 2008 22:35:32 +0000 (UTC)
Newsgroups digitalmars.D

Reply to Benjamin,

> Reply to Sean,
>
>> Does anyone know a way to determine the type and offset of
>> class/struct members?
>> It seems we already have all the necessary pieces, but I haven't been
>> able to get it
>> to work thus far.  What I'm thinking of is something like this:
>> import std.stdio;
>> class C
>> {
>> int i;
>> void* p;
>> }
>> void main()
>> {
>> foreach( e; typeof(C.tupleof) )
>> writefln( e.stringof, " ", e.offsetof );
>> }
>> However, offsetof doesn't appear to work on the members of this
>> TypeTuple, nor on an instance tuple.  I've also tried various
>> attempts
>> at printing the address or value of the instance tuple, with no
>> success.
>> Sean
>>

cleaner:

import std.stdio;

class C
{
int i;
void* p;
}

void main()
{
foreach( i,e; typeof(C.tupleof) )
writefln( e.stringof, " ", C.tupleof[i].offsetof );
}



Recent messages in this thread
 
.# Re: Introspection BCS 23-Sep-2008 06:32 pm