On Wed, 15 Apr 2015 05:31:24 -0400, Jacob Carlborg <[email protected]> wrote:
It needs to be possible to set and get a value of an instance variable
based on it's name, through runtime reflection. It also needs to bypass
protection, i.e. "private".
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?