On 2015-04-15 17:26, bitwise wrote:

Right now, this is the def:

/**
  * Array of pairs giving the offset and type information for each
  * member in an aggregate.
  */
struct OffsetTypeInfo
{
     size_t   offset;    /// Offset of member from start of object
     TypeInfo ti;        /// TypeInfo for this member
}

If "string name" esd added, and then offTi[] esd actually populated,
then I suppose you could do this:

class Test {
     int a = 4;
     private int b = 5;
     void print(){ writeln(b); }
}

void main()
{
     Test test = new Test;
     // offsetof would instead come from the TypeInfo/OffsetTypeInfo
     int* b = cast(int*)(cast(void*)test + Test.b.offsetof);
     *b = 1234;
     test.print();
}

But AFAIK, this is NOT ok in C++ because of the way inheritance works..
is this safe in D?

I'm not sure, I would assume so. Why is this not safe in C++?

--
/Jacob Carlborg

Reply via email to