Difference between revisions of "Intermediate C++ Game Programming Tutorial 19"
From Chilipedia
(→Video Timestamp Index) |
(→Video Timestamp Index) |
||
Line 34: | Line 34: | ||
* Overview of different types of casts [https://youtu.be/g-NGBFCn3co?t=9m30s 9:30] | * Overview of different types of casts [https://youtu.be/g-NGBFCn3co?t=9m30s 9:30] | ||
<div class="mw-collapsible-content"> | <div class="mw-collapsible-content"> | ||
+ | <div class="mw-collapsible mw-collapsed"> | ||
** static_cast | ** static_cast | ||
+ | <div class="mw-collapsible-content"> | ||
*** converts types (int->float etc.) | *** converts types (int->float etc.) | ||
*** casts pointers/references within an inheritance hierarchy (no checking of the validity of the cast!) | *** casts pointers/references within an inheritance hierarchy (no checking of the validity of the cast!) | ||
+ | </div> | ||
** dynamic_cast | ** dynamic_cast | ||
*** casts pointers/references within an inheritance hierarchy (dynamic check!) | *** casts pointers/references within an inheritance hierarchy (dynamic check!) | ||
Line 52: | Line 55: | ||
***<code>Derived* pDerived = (Derived*)pBase;</code> | ***<code>Derived* pDerived = (Derived*)pBase;</code> | ||
*** casted away the constness by accident! | *** casted away the constness by accident! | ||
+ | </div> | ||
</div> | </div> | ||
* Using RTTI (Runtime Type Information) [https://youtu.be/g-NGBFCn3co?t=13m01s 13:01] | * Using RTTI (Runtime Type Information) [https://youtu.be/g-NGBFCn3co?t=13m01s 13:01] |
Revision as of 05:41, 16 October 2019
In this video Chili teaches us how to figure out what our polymorphic pointers are actually pointing to (aka "type discovery"). Just note that although we can do this, it is generally a weaksauce way to go about things. Virtual functions are 1000% more hype than type discovery bullshit. Oh yeah, we also finally see all the C++ style casts united.
Topics Covered
-
dynamic_cast<T*>
anddynamic_cast<T&>
-
const_cast
- Overview of all C++ style casts
- RTTI with
typeid()
- The
type_info
class
Video Timestamp Index
[Expand]
- Using
dynamic_cast<new-type>(expression)
to determine to what derived type a pointer to a polymorphic base type is actually pointing 0:54
- Using
static_cast<>()
to convert pointers within an inheritance hierarchy 6:20
- Using
const_cast<>()
to remove a const from a reference or pointer (yes, you read that right) 7:27
- Overview of different types of casts 9:30
- Using RTTI (Runtime Type Information) 13:01
- The
type_info
class 15:05
- Main take-away 16:40
Source Code
Note that the code for this video is in a different branch called "casting". You will not find it in the master branch.