Static members and operators

Data that belongs to a whole class rather than one object, const correctness, and operator overloading, so that your own types work with +, ==, << and [].

About 6 hours of study

Learning objectives

Lessons

  1. 1

    Static and const members

    A static member belongs to the class, not to each object; const member functions promise not to change the object.

  2. 2

    Operator overloading

    Teach your classes +, ==, [] and <<, as member functions or as friend functions, so they read like built-in types.

Module practice

Module quiz

1. Five objects of a class exist. How many copies of a static data member are there?
2. What does const after a member function's parameter list promise?
3. Which member functions can be called through a const Circle&?
4. Why can a static member function not use this?
5. With Vec operator+(const Vec& o) const as a member, what is this in a + b?
6. Why is operator<< for a class usually a free function rather than a member?
7. Why does operator[] usually return int& rather than int?

‹ Classes and object lifetimeInheritance and polymorphism ›