Hi all,
i am studying a C++ book. Now i am having the chapter struct..so slowly going to classes. The book is ok, makes, but makes me angry from time to time, because the guy mention sth new but used a complicated example...i need help to understand this example :
Code:
struct Person {
string name_;
int age_;
string place_;
};
// i don't get this implementation
std::ostream& operator<<(std::ostream& os, Person p) {
return os << p.name_ << " ("<< p.age_<<") from " << p.place_;
}
int main() {
Person paul {"Paul", 23, "Dresden"};
cout << "You are " << paul << ", right ?\n";
}
what i dont understand is the overloading of <<. especially the parameter list (std::ostream& os, Person p).
in the main.. the usage happens with "<< paul"
where do i see here the parameters , especially std::ostream& os
so i dont really understand neither the implementation nor the usage of it.
would be grateful if someone can explain me this in an understandable way.
i have watched a video about overloading the + operator, and it was easy to understand.
but introducing the overloading in a beginner book with such an example is really mean...there is not even a proper explanation..