c – 自动和复制省略

weixin_38058663 2019-09-12 11:04:38
当使用auto并提交到特定类型时,复制省略的规则究竟是什么? (见:GotW – Almost always auto). 根据我的理解,移动/复制构造函数必须是可访问的,即使它通常不被使用.但是接下来的例子中unique_ptr和fstream之间的区别是什么? (与noexcept有关吗?) #include <memory> #include <fstream> int main() { auto f = std::fstream{"foo.bar"}; auto i = std::unique_ptr<int>{new int}; return 0; } // main.cc:6:10: error: call to implicitly-deleted copy constructor of 'std::basic_fstream<char>' // auto f = std::fstream{"foo.bar"}; // ^ ~~~~~~~~~~~~~~~~~~~~
...全文
18 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_38068653 2019-09-12
  • 打赏
  • 举报
回复
我想你使用libstdc.在这方面,它目前不符合标准,即虽然它们应该具有移动构造器,但它们还没有移动构造器.它将在版本5中修复: Runtime Library (libstdc++) … Full support for C++11, including the following new features: … movable and swappable iostream classes;    从 version 5 changelog

476

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧