我正在尝试编译此代码:
#include <sstream>
std::stringstream foo() {
std::stringstream log;
log << "Hello there\n";
return log;
}
GCC 4.9.2
给了我以下错误(使用-std=c++11
):
[x86-64 gcc 4.9.2] error: use of deleted function
'std::basic_stringstream<char>::basic_stringstream(const std::basic_stringstream<char>&)'
Here一个例子。
由于std::stringstream
有move constructor
,为什么要调用复制构造函数而不是移动构造函数?
注意:从GCC 5
代码正确编译:see here。
答案 0 :(得分:5)
如果我们看一下GCC 5 changes,我们可以看到:
完全支持C ++ 11,包括以下新功能:
- std :: deque和std :: vector符合分配器感知容器要求;
- 可移动和可交换的iostream类;
...
粗体的变化是使你的代码在GCC 5上编译而在4.9上编译失败的原因,移动构造函数还没有为std::stringstream
实现。