Jon*_*let 10 c++ ofstream c++11
我有这个地图,在MSVC10中编译得很好:
std::map<std::string, std::ofstream> m_logFiles;
Run Code Online (Sandbox Code Playgroud)
但是在使用g ++ 4.5并启用了C++ 0x的ubuntu上,我收到以下错误消息:
/usr/include/c++/4.5/bits/ios_base.h| 785|error:'std :: ios_base :: ios_base(const std :: ios_base&)'是私有的
通过使用指针而不是对象,我解决了问题.
在网上搜索,我了解到流不是要复制的(为什么有很好的解释).但我的问题是,std :: ofstream是一个可移动的类型吗?如果是,它不应该允许它作为标准容器中的模板参数使用吗?
如果是,那么在这一点上g ++背后是MSVC10吗?(这可以解释为什么它适用于MSVC).我知道要求编译器编写者完全实现甚至不是最终的东西是愚蠢的,但我对未来感到好奇.
使用g ++ 4.6.1没有帮助.
编辑:阅读我进一步挖掘的评论,发现插入导致问题,而不是地图的声明.
阅读Cubbi的链接我尝试了以下内容:
#include <string>
#include <fstream>
#include <map>
using namespace std;
int main()
{
map<string, ofstream> m_logFiles;
ofstream st;
m_logFiles.insert(make_pair<string, ofstream>(string("a"), move(st)));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但仍然没有运气.g ++抱怨使用b删除的拷贝构造函数.
std::ofstream是可移动的.这个程序使用clang/libc ++为我编译:
#include <string>
#include <fstream>
#include <map>
int main()
{
std::map<std::string, std::ofstream> m_logFiles;
}
Run Code Online (Sandbox Code Playgroud)
参考27.9.1.11 [ofstream.cons].
| 归档时间: |
|
| 查看次数: |
2673 次 |
| 最近记录: |