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 …