Home:ALL Converter>Why can't I pass an rvalue std::stringstream by value to a function?

Why can't I pass an rvalue std::stringstream by value to a function?

Ask Time:2013-12-15T10:03:44         Author:uk4321

Json Formatter

Why does this code not compile?

#include <sstream>

void f(std::stringstream) { }

int main() {
    f(std::stringstream{});
}

I get this error:

error: use of deleted function ‘std::basic_stringstream<char>::basic_stringstream(const std::basic_stringstream<char>&)’
         f(std::stringstream{});
                              ^

If I replace std::stringstream with another type that's noncopyable it works fine. Shouldn't this use stringstream's move constructor?

Author:uk4321,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/20590449/why-cant-i-pass-an-rvalue-stdstringstream-by-value-to-a-function
yy