lectures.alex.balgavy.eu

Lecture notes from university.
git clone git://git.alex.balgavy.eu/lectures.alex.balgavy.eu.git
Log | Files | Refs | Submodules

type-confusion-cpp.md (686B)


      1 +++
      2 title = 'Type confusion (C++)'
      3 +++
      4 # Type confusion (C++)
      5 C++ provides classes, like structs that tie data to functions.
      6 Class instance known as 'object'.
      7 
      8 Stack objects have constructor and destructor automatically called.
      9 
     10 Heap objects managed with new/delete which call constructor/destructor.
     11 
     12 Typecasts:
     13 - `reinterpret_cast`: no checks, assumes programmer know what they're doing
     14 - `static_cast`: compile-time check, allows any cast that might be valid (including parent-to-child)
     15 - `dynamic_cast`: run-time check, ensures runtime type is consistent with compile-time type
     16 
     17 Type confusion: object may be cast to wrong type, members read and written according to the wrong type