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() { std::cout << “Fraction(” << m_numerator << “, ” << m_denominator << “)\n”; } }; int main() …

21.8 — Overloading the increment and decrement operators

Overloading the increment (++) and decrement (–) operators is pretty straightforward, with one small exception. There are actually two versions of the increment and decrement operators: a prefix increment and decrement (e.g. ++x; –y;) and a postfix increment and decrement (e.g. x++; y–;). Because the increment and decrement operators are …

21.5 — Overloading operators using member functions

In lesson , you learned how to overload the arithmetic operators using friend functions. You also learned you can overload operators as normal functions. Many operators can be overloaded in a different way: as a member function. Overloading operators using a member function is very similar to overloading operators using …