23.6 — Container classes

In real life, we use containers all the time. Your breakfast cereal comes in a box, the pages in your book come inside a cover and binding, and you might store any number of items in containers in your garage. Without containers, it would be extremely inconvenient to work with …

23.3 — Aggregation

In the previous lesson , we noted that object composition is the process of creating complex objects from simpler ones. We also talked about one type of object composition, called composition. In a composition relationship, the whole object is responsible for the existence of the part. In this lesson, we’ll …

23.2 — Composition

In real-life, complex objects are often built from smaller, simpler objects. For example, a car is built using a metal frame, an engine, some tires, a transmission, a steering wheel, and a large number of other parts. A personal computer is built from a CPU, a motherboard, some memory, etc… …

14.10 — Constructor member initializer lists

This lesson continues our introduction of constructors from lesson . Member initialization via a member initialization list To have a constructor initialize members, we do so using a (often called a “member initialization list”). Do not confuse this with the similarly named “initializer list” that is used to initialize aggregates …

LearnCpp.com tutorials: Now with syntax highlighting!

Yup, it’s finally here. If you have a javascript enabled browser, code examples in the tutorials will now have line numbering and syntax highlighting. For example, instead of: Cents& Cents::operator= (const Cents &cSource) { // check for self-assignment by comparing the address of the // implicit object and the parameter …

14.14 — Introduction to the copy constructor

Consider the following program: #include <iostream> class Fraction { private: int m_numerator{ 0 }; int m_denominator{ 1 }; public: // Default constructor Fraction(int numerator=0, int denominator=1) : m_numerator{numerator}, m_denominator{denominator} { } void print() const { std::cout << “Fraction(” << m_numerator << “, ” << m_denominator << “)\n”; } }; int …