Reputation: 2127
My friend sent me a code where he says sucessfuly compiled in Windows. I tried on linux and it failed giving the error below. Below is a minimum verifiable example of the code.
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
std::stringstream ss, sl;
sl << ss;
}
but it gives
error: cannot bind ‘std::basic_ostream’ lvalue to ‘std::basic_ostream&&’
sl << ss;
Why it works in windows but not in linux, and why this error happens?
Upvotes: 1
Views: 198
Reputation: 141554
Since C++11 this code fails to compile because there is no matching overload for operator<<
with both operands of type std::stringstream
.
However, prior to C++11, std::ostream
provided implicit conversion to void *
, so the following overload could be called:
basic_ostream& operator<<( const void* value );
The output would be the same as outputting a null pointer if the stream has an error, otherwise some unspecified non-null pointer value.
Probably your friend used an old compiler, or a compiler running in old compatibility mode .
Upvotes: 3