Your include
's should look like this:
Person.cpp:
#include <iostream>
#include <string>
#include "Person.hpp"
Employee.cpp:
#include <iostream>
#include <string>
#include "Employee.hpp"
main.cpp
#include <iostream>
#include <string>
#include <vector>
#include "Person.hpp"
#include "Employee.hpp"
#include "Friend.hpp"
That is, each .cpp
(implementation) includes the respective .hpp
(interface) along with additional headers needed (like <string>
). Your main.cpp
includes all needed headers but no other .cpp
file. The compiler will parse all .cpp
files individually and the linker will link the results into an executable. As a rule of thumb, never include a .cpp
anywhere.
The specific error is when the compiler sees
void Employee::Print()
and doesn't know what Employee
is. Including Employee.hpp
fixes this by bringing in Employee
's definition.