是ifsteam的移动构造函数是否隐式删除? [英] Is the move constructor of ifsteam implicitly deleted?

查看:220
本文介绍了是ifsteam的移动构造函数是否隐式删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下简单的类:

class Source
{
public:
    Source() = default;
    Source(Source const&) = delete;
    Source(Source&&) = default;

    explicit Source(std::string const& fileName)
     : inputStream(fileName), path_(fileName)
    {}

    ~Source() = default;

    auto path() const -> std::string
    {
        return this->path_;
    }

    std::ifstream inputStream;
private:
    std::string path_;
};

auto main(int argc, char* argv[]) -> int
{
    Source source(Source("test.txt"));
    cout << source.path() << "\n";

    return 0;
}

根据 cppreference ifstream 有一个 move 构造函数,当我尝试用 MinGW 4.7.2 编译时,我得到以下错误:

According to cppreference ifstream has a move constructor, but when I try to compile that with MinGW 4.7.2, I get the following error:


.. \src\main.cpp:32:46:错误:使用删除的函数
'cy :: Source :: Source(cy :: Source&&)'
..\src\main.cpp:10:0:source.hpp:28:5:note:
'cy :: Source :: Source(cy :: Source& '被隐式删除,因为
的默认定义会是错误的:source.hpp:28:5:error:use
删除函数'std :: basic_ifstream :: basic_ifstream(const
std :: basic_ifstream&)'
c:\mingw\bin ../ lib / gcc / mingw32 / 4.7.2 / include / c ++ / fstream:420:11:
note: :basic_ifstream :: basic_ifstream(const
std :: basic_ifstream&)'被隐式删除,因为默认的
定义将是错误的:
c:\mingw\bin ../ lib /gcc/mingw32/4.7.2/include/c++/fstream:420:11:
错误:使用已删除的函数
'std :: basic_istream :: basic_istream(const
std :: basic_istream&)'

..\src\main.cpp:32:46: error: use of deleted function 'cy::Source::Source(cy::Source&&)' In file included from ..\src\main.cpp:10:0: source.hpp:28:5: note: 'cy::Source::Source(cy::Source&&)' is implicitly deleted because the default definition would be ill-formed: source.hpp:28:5: error: use of deleted function 'std::basic_ifstream::basic_ifstream(const std::basic_ifstream&)' c:\mingw\bin../lib/gcc/mingw32/4.7.2/include/c++/fstream:420:11: note: 'std::basic_ifstream::basic_ifstream(const std::basic_ifstream&)' is implicitly deleted because the default definition would be ill-formed: c:\mingw\bin../lib/gcc/mingw32/4.7.2/include/c++/fstream:420:11: error: use of deleted function 'std::basic_istream::basic_istream(const std::basic_istream&)'

我做错了什么?或者cppreference的文档是不准确的?或者GCC 4.7.2有一个错误?

Am I doing something wrong? Or the documentation of cppreference is inaccurate? Or GCC 4.7.2 has a bug?

推荐答案

结果是GCC的标准库实现还没有实现和交换操作的流类。有关C ++ 11功能的当前状态的详细信息,请参见这里

It turns out that the standard library implementation of GCC has not implemented yet the move and swap operation for the stream classes. See here for detail about the current status of C++11 features in the gcc standard library.

感谢 Jesse Good 以提供信息和链接。

Thanks Jesse Good for giving the information and link.

这篇关于是ifsteam的移动构造函数是否隐式删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆