On Wed, 15 Apr 2015 11:26:48 -0400, bitwise <[email protected]> wrote:
But AFAIK, this is NOT ok in C++ because of the way inheritance works..
is this safe in D?
To clarify, I'm talking about doing doing things by Object pointer or void
pointer, which seems to work fine:
class Test {
int a = 4;
private int b = 5;
void print(){ writeln(b); }
}
struct Test2 {
int a = 4;
private int b = 5;
void print(){ writeln(b); }
}
void main()
{
Test test = new Test;
Object obj = test;
int* b = cast(int*)(cast(void*)obj + Test.b.offsetof);
*b = 1234;
test.print();
Test2 test2 = Test2();
void *obj = &test2;
int* b = cast(int*)(obj + Test2.b.offsetof);
*b = 1234;
test2.print();
}