Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


#ActualKing Mir

Posted 03 May 2013 - 01:58 PM

I also said, and so did you, that C-style cast will do a reinterpret_cast if it cannot do the static_cast. When reinterpret_cast is the wrong thing to do in those cases, then so is the C-style that incorrectly proceeds with the cast. It changes the behavior of the cast, and the casting behavior between the two is different in multiple inheritance.

The behavior of a c-style cast is always the same as a static cast, when a static cast is possible, which is is when upcasting multiple ingerritance. So the C cast will correctly upcast.

When static_cast doesn't work, reinterpret cast is probably not wrong; it's the only option. However, it might hide a bug where you expect static cast to be possible, but it isn't. The bug is likely elsewhere, but using static_cast may help catch it, turning a runtime error into a compile time error. But again, this has little to do with multiple inherritance.

#1King Mir

Posted 03 May 2013 - 01:49 PM

I also said, and so did you, that C-style cast will do a reinterpret_cast if it cannot do the static_cast. When reinterpret_cast is the wrong thing to do in those cases, then so is the C-style that incorrectly proceeds with the cast. It changes the behavior of the cast, and the casting behavior between the two is different in multiple inheritance.

The behavior of a c-style cast is always the same as a static cast, when a static cast is possible, so what you say here is incorrect. The C cast will not incorrectly upcast when using multiple inherritance.

C style cast are bad, but not for reasons to do with multiple inherritance.

PARTNERS