Correct answer to quiz question - add resident to City class?

i would like to know the right answer in this quiz question:
Define a method .add_resident() for a City class. (This method is defined in a .cpp file, not inside the class.) City has a population attribute that tracks the number of residents.

this is my wrong answer:
#include “city.hpp”
City::add_resident add_resident() { population++; }

When you define methods c++ wants to know what the return type is, if any.
So, on the second line the first box needs to be the return type (there isn’t one in this case so it’s ‘void’).
The second box is the methods name - City::add_resident

1 Like