I have a question about something in this lesson:
In the first picture, there is the code:
// city.hpp
#include "city.hpp"
class City {
std::string name;
int population;
public:
City(std::string new_name, int new_pop);
};
//city.cpp
City::City(std::string new_name, int new_pop)
// members get initialized to values passed in
: name(new_name), population(new_pop) {}
I do not understand why we have #include “city.hpp” in the city.hpp section. Is this a typo? Shouldn’t the #include “city.hpp” be under the // city.cpp instead, like this?
//city.cpp
#include "city.hpp"
City::City(std::string new_name, int new_pop)
// members get initialized to values passed in
: name(new_name), population(new_pop) {}
This image has me confused. Also, wouldn’t the city.hpp need #include string at the top? Like this:
// city.hpp
#include <string>
class City {
std::string name;
int population;
public:
City(std::string new_name, int new_pop);
};
Thanks.