Now that you have a class, let’s create some objects! To refresh your memory, an object is an instance of a class, which encapsulates data and functionality pertaining to that data.
To create (or instantiate) an object, we can do this:
We can give the object’s attributes values like this (note that these must be attributes you defined in the class):
accra.population = 2270000;
Later, we can access this information using the method we added to the
City class (if it’s in a
public part of the class):
Flip over to song.hpp and song.cpp to see how the class and its methods are set up.
Then, in music.cpp, instantiate a new song
.add_title() method to add a title to
.get_title() to retrieve
electric_relaxations title and print it to the terminal.