>> #include <fstream>
>> void main()
>> {
>> std:
fstream("dummy") << "hello" << std::endl;
>> }
> he expression
> std:
fstream("dummy")
> is a temporary object. As such, it cannot be bind to a non-const
> reference, which the global function
> operator<<(ostream &, const string &)
> expects. So, the compiler cannot make this choice in your code.
A follow-up question on this;
Personally my first guess that the temporary object remains in scope, until
the closing bracket '}' takes place, but then I wrote out the operator<<
calls...
The first operator << translates into "std:

fstream& operator
<<(std:

fstream&, std::string)".
To me it would indicate that the constructor of the temporary object takes
place in the parameter list of this FIRST operator<< call. To me sounded as
if the object's scope is limited to that of the method it's created in.
Since the return value of this call is then used in the second call (the
one featuring std::endl), does this mean that the first operator<< returns
a reference to a locally-defined object?
Sounds like this (returning a reference to a locally-defined object)
results in undefined behaviour. Is this assumption correct?
Kind regards,
Johan