13.9 — Destructors

A destructor is another special kind of class member function that is executed when an object of that class is destroyed. Whereas constructors are designed to initialize a class, destructors are designed to help clean up. When an object goes out of scope normally, or a dynamically allocated object is …

13.5 — Constructors

When all members of a class (or struct) are public, we can use to initialize the class (or struct) directly using list-initialization: class Foo { public: int m_x {}; int m_y {}; }; int main() { Foo foo { 6, 7 }; // list-initialization return 0; } However, as soon …

6.2 — User-defined namespaces and the scope resolution operator

In lesson , we introduced the concept of naming collisions and namespaces. As a reminder, a naming collision occurs when two identical identifiers are introduced into the same scope, and the compiler can’t disambiguate which one to use. When this happens, compiler or linker will produce an error because they …

12.4 — Recursion

A recursive function in C++ is a function that calls itself. Here is an example of a poorly-written recursive function: #include <iostream> void countDown(int count) { std::cout << “push ” << count << ‘\n’; countDown(count-1); // countDown() calls itself recursively } int main() { countDown(5); return 0; } When countDown(5) …