Lecture overview -- Keyboard shortcut: 'u'  Previous page: Value return -- Keyboard shortcut: 'p'  Next page: Implicit type conversions -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 2 - Page 22 : 42
Notes about C++
Basic facilities
Type conversion - Grand Overview

The purpose of this page is to give an overview of implicit and explicit type conversion in C++

  • The C++ Programming Language: Page 130-131, 408, 819
 

  • 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)

Item 2 of More Effective C++ has some basic arguments in favor of 'the new C++ casts' in contrast to C-style casts.