Once a matching opCast is declared in a class, it is no longer possible to obtain the instance pointer needed for memory deallocation.
class Foo {
auto opCast(T)() {
return this;
}
}
void main() {
Foo foo = new Foo;
void* ptr = cast(void*)foo; // Error: cannot implicitly convert expression `foo.opCast()` of type `example.Foo` to `void*`
}