Your own types and the standard library

Defining structs and classes, then using the containers and algorithms that make up the heart of everyday C++.

About 13 hours of study

Learning objectives

Lessons

  1. 1

    Structs and your first class

    Group related data with struct, then protect it in a class with private members, a constructor and methods.

  2. 2

    Maps and sets

    Look values up by key with map, keep unique sorted values with set, and choose between ordered and unordered containers.

  3. 3

    Stacks, queues and pairs

    Choose the right container for the order you need: stack, queue, deque, priority_queue, and pair for two values together.

  4. 4

    Iterators and algorithms Intermediate

    Walk containers with iterators, and use the standard algorithms to sort, search, count and transform instead of writing loops by hand.

Module practice

Module quiz

1. What is the only language difference between struct and class?
2. How should you test whether a key is in a map, without adding it?
3. Which container suits an Undo feature?
4. Why must you not read *v.end()?
5. What must be done before using unique to remove all repeats?
6. A compare function for sort should use which comparison?

‹ Functions and everyday dataGoing further ›