I have the following simple class:
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() << "
";
return 0;
}
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:
..srcmain.cpp:32:46: error: use of deleted function 'cy::Source::Source(cy::Source&&)' In file included from ..srcmain.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:mingwin../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:mingwin../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&)'
Am I doing something wrong? Or the documentation of cppreference is inaccurate? Or GCC 4.7.2 has a bug?
See Question&Answers more detail:os