On Monday, 27 July 2015 at 13:11:33 UTC, anonymous wrote:
In the first example, you pass a pointer to a class instance. You cannot get the vtbl entry for the interface like this. Instead try to do this in 2 steps:

actually i meant you pass an untyped pointer, so when you cast as interface it's not like if the vtbl of an object is queried. So you have to upcast to an Object then cast to the interface, which is not a simple cast (it get something in the virtual table.

void testDispathcer(void *rawSelf) {
    auto obj = cast(Object) rawSelf; // reinterpret
auto self = cast(TestInterface) obj; // get vtbl entry , it's not a simple cast
    // works
    self.testMethod();
}


Reply via email to