Careful about putting function definitions in the header file. You either need to inline the definition or, better yet, put it in a .cpp
file instead. In Customer.h
just put a function prototype:
// Customer.h
std::ostream& operator << (std::ostream& output, Customer& customer);
And put the full definition in Customer.cpp
:
// Customer.cpp
std::ostream& operator << (std::ostream& output, Customer& customer)
{
output << "First Name: " << customer.getFirstName() << " "
<< "Last Name: " << customer.getLastName() << std::endl;
return output;
}
Alternatively, if you really want the definition in the header file then add the inline
keyword. Inline definitions have to go in header files, and by their nature they don't have external linkage and won't trigger duplicate definition errors.
inline std::ostream& operator << (std::ostream& output, Customer& customer)
{
...
}