std.reflection prototype
bitwise via Digitalmars-d
digitalmars-d at puremagic.com
Wed Apr 15 10:45:15 PDT 2015
On Wed, 15 Apr 2015 11:26:48 -0400, bitwise <bitwise.pvt at gmail.com> 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();
}
More information about the Digitalmars-d
mailing list