Difference between revisions of "Intermediate C++ Game Programming Tutorial 18"

From Chilipedia
Jump to: navigation, search
(Errata)
(Errata)
(One intermediate revision by the same user not shown)
Line 11: Line 11:
 
=== Part 2 ===
 
=== Part 2 ===
 
* Using inheritance and composition together
 
* Using inheritance and composition together
 +
* Basic idea of a polymorphic state machine and its application to entity behavior
  
 
== Video Timestamp Index ==
 
== Video Timestamp Index ==
Line 22: Line 23:
 
* Forgot the virtual destructor for <code>class Weapon</code>! (this one hurts)
 
* Forgot the virtual destructor for <code>class Weapon</code>! (this one hurts)
 
* In the children, the function signatures should be: <code>int CalculateDamage( const Attributes& attr,Dice& d ) const override</code>
 
* In the children, the function signatures should be: <code>int CalculateDamage( const Attributes& attr,Dice& d ) const override</code>
* Though not technically an error, it might have been a better decision to make Weapon::GetName() and Weapon::GetRank() (pure) virtual functions (this would reduce the amount of per-instance data to just the vtable ptr)
+
* Though not technically an error, it might have been a better decision to make <code>Weapon::GetName()</code> and <code>Weapon::GetRank()</code> (pure) virtual functions (this would reduce the amount of per-instance data to just the vtable ptr)
  
 
== See also ==
 
== See also ==
 
* [[Intermediate C++ Game Programming Tutorial 19|Next in series (Tutorial 19)]]
 
* [[Intermediate C++ Game Programming Tutorial 19|Next in series (Tutorial 19)]]
 
* [[Intermediate C++ Game Programming Series]]
 
* [[Intermediate C++ Game Programming Series]]

Revision as of 11:21, 13 December 2017

Another two-parter here, and we got the real stuff now. Virtual functions allow you to unlock the true potential of inheritance in C++. You need to know this shit.

Topics Covered

Part 1

  • How to create a virtual function
  • Using the override keyword
  • Creating a pure virtual function
  • Using a container of pointers to manage a heterogeneous collection of objects
  • virtual destructors

Part 2

  • Using inheritance and composition together
  • Basic idea of a polymorphic state machine and its application to entity behavior

Video Timestamp Index

Source Code

Inheritance Github Repository

Errata

  • Forgot the virtual destructor for class Weapon! (this one hurts)
  • In the children, the function signatures should be: int CalculateDamage( const Attributes& attr,Dice& d ) const override
  • Though not technically an error, it might have been a better decision to make Weapon::GetName() and Weapon::GetRank() (pure) virtual functions (this would reduce the amount of per-instance data to just the vtable ptr)

See also