September 2017
Beginner to intermediate
384 pages
9h 18m
English
We can increase the abstraction level of our algorithms via the techniques of classical object-oriented (OO) programming, as seen in languages such as Java and C#. The OO approach is to decide exactly which behaviors we'd like to be customizable, and then declare them as the public virtual member functions of an abstract base class:
class container_of_ints { public: virtual int size() const = 0; virtual int& at(int) = 0; }; class array_of_ints : public container_of_ints { int data[10] = {}; public: int size() const override { return 10; } int& at(int i) override { return data[i]; } }; class list_of_ints : public container_of_ints { struct node { int data; node *next; }; node *head_ = nullptr; int size_ = ...Read now
Unlock full access