No I dont modify the object
And the object is array of ten integers ,s is the size of the array
practice.cpp|20|error: 'std::ostream& MyObj::operator<<(std::ostream&, MyObj&)' must take exactly one argument|
\practice.cpp||In member function 'MyObj& MyObj::operator+(MyObj&)':|
practice.cpp|29|warning: reference to local variable 'temp' returned [enabled by default]|
||=== Build finished: 1 errors, 1 warnings ===|
o.operator<<(out); kind of defeats the purpose of operator overloading, ¿don't you think?
cire wrote:
you'll also need a helper function outside the class definition: ostream& operator<<(ostream&out, const MyObj& o);
you can skip the definition of operator<< in the class and make the stand-alone function a friend
Why don't you? It's more clear than o << out. You aren't inserting out into o. All we were doing was forwarding to our overloaded class operator, and that's much clearer with an explicit call.
This is entirely a matter of style. No semantics were changed.
I would simply skip the member operator and go with the stand-alone. print_at is an inaccurate description. out could be a file stream, a console stream, a stringstream. Conceptually, we're inserting data into a stream, so if I went the named method route, I'd be more likely to use insert(out) taking an output iterator as the parameter type.