C++ · Beginner level

Beginner level · Module 4 of 5 · 11 guided hours

References, Pointers and First Classes

Understand memory addresses, references and pointers, and model real things with simple classes.

Learning objectives

  • Explain references and pointers and use them correctly
  • Avoid null and dangling pointers
  • Write a class with private data, a constructor and member functions

Topics

  • memory and addresses
  • references
  • pointers, & and *
  • nullptr
  • classes and access specifiers
  • constructors and member functions

Lessons

  1. Lesson 1 References and Pointers

    See how variables live at memory addresses, and use references and pointers to refer to them.

    address-of &dereference *nullptrdangling pointer

  2. Lesson 2 Your First C++ Class

    Define a class with private data and public member functions, and create objects from it.

    classpublic and privatemember functionobject

  3. Lesson 3 Constructors and Keeping Objects Valid

    Initialise objects with constructors and member initializer lists, and enforce rules in member functions.

    constructormember initializer listinvariantstd::invalid_argument

Practical activity

Write a WaterPoint class with a name, a daily reading and a status, and a function that marks points below a threshold as needing repair.

Expected outcomes

  • Correct use of references and pointers in small programs
  • Simple, encapsulated classes

Assessment

Short written check on references versus pointers, plus a practical class exercise reviewed against a checklist.

Free taster lesson Pointers, References & Classes Read a free self-study lesson on this topic in the Free Course Library.

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.