If we use multiple inheritance, slicing will make the addresses for the parent objects different from the address to the sheet objects:
struct X {int x}; struct Y {int y}; struct Z : X, Y {int z};
So, if we have an object Z Z , its address &z will not coincide with the address of its parent Y : static_cast<Y*>(&z) is four bytes higher than &z .
The good thing about static_cast is that it is, well, static, so it does not take time to run (compared to dynamic_cast , that is). However, if we have a Z* that points to 0 , each cast to the parent must and should also give a null pointer. Why does it work and how is it implemented? Does this mean that every static_cast introduces a branch instruction?
source share