Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

What good is static_cast anyway?

good static_cast
0
Posted

What good is static_cast anyway?

0

In spite of all the verbal stunts and pedagogy, there’s no escape from admitting that static_cast is really useless. Almost every static_cast expression is redundant since the conversion would take place even if you didn’t use that operator at all. Examples of such redundant casts include: • Conversion of base classes to derived classes, including pointers and references Derived *p= static_cast (pbase); • Conversions from one numeric type to another: int result= static_cast(12.56); • Conversion to void*: void*opaque= static_cast (&myobj); Stroustrup concludes: “because static_cast is so ugly and so relatively hard to type, you’re more likely to think twice before using one”. I agree.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123