Skip to main content

Section 21.9 Complex Collections

Much like how we can make a vector of vectors to create a 2D table, we can also make collections that contain other collections of different types. This allows us to create more complex data structures.
For example, we might want to represent all the models of cars made by different manufacturers. We could use a map where the keys are the manufacturer names (strings) and the values are vectors of model names (also strings). This way, we can easily look up all the models for a given manufacturer. The type for such a collection would be:
map<string, vector<string>> carModels;
The keys in this map are strings like "Toyota" or "Ford". Each value is a vector, like: {"Camry", "Corolla", "Prius"}. Here is an example of what using it might look like:
Listing 21.9.1.

Checkpoint 21.9.1.

Arrange blocks to declare a collection called classList that is a map which lets us use Course objects to loop up vectors of Student objects.
You have attempted of activities on this page.