ostream& operator << (ostream &os, const foo &f) { for (int i = 0; i < fasize(); ++i) os << fa[i] << " "; os << endl;
not manorial. Segfact is caused by the fact that you do not return os
ostream& operator << (ostream &os, const foo &f) { for (int i = 0; i < fasize(); ++i) os << fa[i] << " "; return os;
this behavior is undefined unless you return ostream. endl cleans your os here. That is why it seems to work.
EDIT: Why does he work in this case according to Bo Persson
. os <arps; this is another statement that actually returns os by placing it "where the expected value is expected" (probably case). When the code returns another level in main, the link to os is still there
user995502
source share