try name.print_info() instead of cout << name
your attempt to cout name ... name lacks a friendly << operator or I missed it so you can't stream it. Instead of a convoluted friend stream operator, you can also have your object cast itself to string and then you can print it. you may have to say cout << (string)name if you do that, as those sometimes don't care to be implicit casts, but its another way to defur the feline.
also, range based for loops would do well with a reference:
for( Friend &name: ... ///avoids copy of a fat object every iteration! ideally also make it const.
also, global data is not good design in larger programs, move friends list to main and pass as a parameter and get used to that as a best practice /habit.
examples:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
struct derp
{
int x;
operator string() {return "my value is:"s + to_string(x);}
friend ostream& operator<<(ostream& os, const derp& d)
{ os << d.x; return os; }
};
int main()
{
derp d;
d.x = 42;
cout << (string)d << endl;
cout << d;
}
|
while the stream operator is nice, I usually want a string.. I almost never output to a console, but I frequently output to a GUI widget... and its minor to use some sort of stringify for both while getting the string out of the stream is annoying (not hard, just cluttery).