I have class A and method a().
I have class B : public A and new method b().
I can call b from A like reinterpret_cast<B*>(this)->b();
If I am 100% sure that this A instance is B, not just A, is it
1) always safe to do like this?
2) faster than virtual call?
> reinterpret_cast<B*>(this)->b();
> If I am 100% sure that this A instance is B, not just A, is it
> 1) always safe to do like this?
No, it is not safe.
If it is guaranteed that the dynamic type of the object pointed to by this is B or a derived class of B (and B does not inherit virtually from A), static_cast<B*>(this)->b(); is safe.
> 2) faster than virtual call?
Yes. Particularly if B::b() is inlineable. Marginally otherwise.