| | Basic facilities - slide 26 : 46 |
Type conversion - Grand Overview
The purpose of this page is to give an overview of implicit and explicit type conversion in C++
- Implicit conversions
- Between built-in, fundamental (numeric) types - some details next page
- Between user-defined types and built-in types
- Via constructors and conversion operators
- More details in the next lecture
- In between user defined types
- Explicit conversions to type T:
- C-style type casts: (T)expr or T(expr) using early C++ notation
- static_cast<T>(expr) from a related type
- reinterpret_cast<T>(expr) from an unrelated type - "dangerous"
- dynamic_cast<T*>(expr) from a related polymorphic type (pointer or reference types only)
- const_cast<T>(expr) from a closely related type (add or remove const qualifier)