Object memory layout

https://www.youtube.com/watch?v=_go74QpFPAw

https://www.youtube.com/watch?v=SuubuqI4gVA

Objects

creation

order of construction

object is constructed in this order: 1) its virtual base gets constructed, 2) then its base, 3) then its members, 4) then the constructor body runs

destruction order is in the exact reverse order

access modifier

3 types: public, protected, private

Access modifiers are only checked in compile time. During runtime, it will not be checked. This leads to that you can even execute a private virtual method in runtime if it is declared as public in a base class and is object sliced…

a method can be public in base but private in derived…

mutable

use “mutable” keyword to specify a member variable is mutable even in const functions

this is useful for variables that are not part of the object state, e.g. caches, mutexes