error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'

梦想的初衷 提交于 2019-11-29 10:58:59

You are trying to copy a stream, which is not possible.

To help you avoid that, one of the base classes has a private copy constructor.

Bo Persson

The offending lines are,

ifstream readRoom( checkStudentFST ); 

and,

ifstream readRoom( checkStudentSND );  

where you are trying to copy an existing stream, instead of perhaps opening it with the file name.

From your error, I can make a guess that you are trying to overload operator << or operator >> with fstream (or ostream) for your own class object.

Somehow you have missed to mention that operator << function as friend of your class. Your code should be looking like this snippet. See in carefully that data members are made public for the target class.

The problem can occur if You are setting a class parameter (which is making a copy of the object) in a constructor, like this:

class Test
{
public:
    Test() {}
    Test(FileHandler fh_) : fh(fh_) {}
    // ...
private:
    FileHandler fh;
};

If the FileHandler class contains a member which is a file stream, You will get the error, just as I did.

SOLUTION: Changing the constructor parameter from FileHandler fh_ to FileHandler* fh_.

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