Temporary non-const istream reference in constructor (C++)
- by Christopher Bruns
It seems that a constructor that takes a non-const reference to an istream cannot be constructed with a temporary value in C++.
#include <iostream>
#include <sstream>
using namespace std;
class Bar
{
public:
explicit Bar(std::istream& is) {}
};
int main()
{
istringstream stream1("bar1");
Bar bar1(stream1); // OK on all…