Can't declare ifstream class member in header file

时光怂恿深爱的人放手 提交于 2019-12-01 10:57:43

The problem is that std::ifstream doesn't have a public copy constructor (because copying one wouldn't make sense) but the compiler-generated copy constructor for your class wants to use it.

It doesn't have any available assignment operator for the same reason (i.e. copying a std::ifstream is nonsense).

You should disallow copying and assignment for your class as well.

A simple way is to add

private:
    ReadFile(const ReadFile&);
    ReadFile& operator=(const ReadFile&);

to your class, if you're using C++03.

In C++11, use the = delete syntax.

public:
    ReadFile(const ReadFile&) = delete;
    ReadFile& operator=(const ReadFile&) = delete;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!