100DaysOfGameDev: Day 28

Who-hoo! Back again to the C++ book. Today's topic was “derived classes”. We looked into what simple derived classes can do, that is to simply add new data fields to the base type, and also when you add new functionality. Member functions were explained in great detail to explain when you would want to override them in the derived class. Two methods of overriding function behavior were presented. First clumsy ( fine for a small codebase with a single developer ) solution was to store a type field and slam all the logic implementation into a single function, where based on a type you execute certain code and use static_cast to access fields. Second way ( much neater ) was to use virtual function. Also, when using virtual functions you can use helper context keywords such as override, final to explicitly tell the user what they can and cannot do with a method, such as overriding, or prohibiting to overwrite the method in base. Furthermore, the usage of using keyword was discussed since classes are technically namespaces anyways and you can bring so functions from another class, or even inherit constructors. Finally, the return type relaxation a.k.a covariant return rule was explained, which I belive is same as in Java and is quite useful if you want to return derived type in a derived method. That's it for today, see you tomorrow!