About 64,300 results
Open links in new tab
  1. Regular cast vs. static_cast vs. dynamic_cast - Stack Overflow

    Aug 26, 2008 · An "up-cast" (cast to the base class) is always valid with both static_cast and dynamic_cast, and also without any cast, as an "up-cast" is an implicit conversion (assuming the …

  2. When should static_cast, dynamic_cast, const_cast, and reinterpret_cast ...

    Maybe a good reference here: How do you explain the differences among static_cast, reinterpret_cast, const_cast, and dynamic_cast to a new C++ programmer?.

  3. Why use static_cast<T>(x) instead of (T)x? - Stack Overflow

    Sep 19, 2008 · I've heard that the static_cast function should be preferred to C-style or simple function-style casting. Is this true? Why?

  4. What is the difference between static_cast<> and C style casting?

    In short: static_cast<>() gives you a compile time checking ability, C-Style cast doesn't. static_cast<>() is more readable and can be spotted easily anywhere inside a C++ source code, C_Style cast is'nt. …

  5. c++ static_cast and references - Stack Overflow

    Oct 30, 2013 · You can use static_cast to downcast lvalues to references of derived classes, because there's no implicit cast for that way (as opposed to converting from a derived to a base class). You …

  6. Should I use static_cast or reinterpret_cast when casting a void* to ...

    Nov 21, 2008 · The static_cast is more appropriate for converting a void* to a pointer of some other type. static_cast is the cast of choice when there is a natural, intuitive conversion between two types that …

  7. What happens if you static_cast invalid value to enum class?

    More generally, as you cast from the underlying type to the enumeration type, no value in data[0] can lead to UB for the static_cast. After CWG 1766 (C++17) See CWG defect 1766. The …

  8. casting - How to cast int to enum in C++? - Stack Overflow

    May 28, 2017 · @KirillKobelev I'm not using a static_cast because it does anything different from a C style cast, I'm using static_cast because C++ casts are stylistically preferable to C casts.

  9. How is static_cast implemented in c++? - Stack Overflow

    Dec 9, 2014 · @Emadpres: A C-style cast will do exactly the same thing as static_cast in this case; the difference is that it can fall back to more dubious conversions in cases where static_cast would fail. …

  10. c++ - Proper way of casting pointer types - Stack Overflow

    Using static_cast to cast a pointer to and from void* is guaranteed to preserve the address. reinterpret_cast on the other hand guarantees that if you cast the pointer from one type to other, and …