April 2020
Intermediate to advanced
412 pages
9h 58m
English
One of the mottos of C++ is You don't pay for what you don't use. This language is packed with many more features than C, yet it promises zero overhead for those that are not used.
Take, for example, virtual functions:
#include <iostream>class A {public: void print() { std::cout << "A" << std::endl; }};class B: public A {public: void print() { std::cout << "B" << std::endl; }};int main() { A* obj = new B; obj->print();}
The preceding code will output A, despite obj pointing to the object of the B class. To make it work as expected, the developer adds a keyword—virtual:
#include <iostream>class A {public: virtual void print() { std::cout << "A" << std::endl; }};class B: public A {public: void print() { ...