Message from C, C++ discussions

January 2020

— That was entertaining as hell to reread. Life lessons and coding best practices from a 16 year old

— 

Never thought I'd see the day where someone who can barely work 40 hours a week legally thinks he knows literally everything about something so diverse

— He used to be half decent before he decided to switch to getting taught programming by a schizophrenic

Message permanent page

— Oh yeah that'll do it

— `ostream & operator <<(ostream &os, Test &r)
{
os<<"\n"<<r.h;
return o;
}`

Why don't we just return os? If os is the reference to cout then why again return reference to os? Isn't reference to os same as refererence to cout?

Message permanent page

— You meant return os right?

— Yeah

— Well look cout is just a global variable of the type ostream

— Maybe someone has their own variable and it that would not work if we return cout

— I didn't get that

— I have a question, when we return by value, the copy of the returned object is created and then that copy is returned so is copy constructor called during this copying?

Message permanent page

— Yep but either the object gets moved or with rtvo (return value optimization) this copy gets eleminated (except maybe for primitives)

Message permanent page