std.reflection prototype

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Wed Apr 15 23:22:25 PDT 2015


On 2015-04-16 01:32, bitwise wrote:

> One reason is that casting with multiple inheritance offsets the
> pointer, and I forget exactly virtual inheritance works, but I'm sure it
> breaks things too..

In D I would assume this would eventually be possible:

class Foo { int a; }
class Bar : Foo { int b; }

Foo f = new Bar;

auto offset = typeid(f).getMemeber("b").offset;
auto ptr = cast(int*)(cast(void*)f + offset);
*ptr = 4;

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list