4

我在 C++ 应用程序中收到此错误:

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

我在 stackoverflow 中看到过类似的问题,但我无法弄清楚我的代码有什么问题。有人能帮我吗?

    //header file
class batchformat {
    public:
        batchformat();
        ~batchformat();
        std::vector<long> cases;        
        void readBatchformat();
    private:
        string readLinee(ifstream batchFile);
        void clear();
};


    //cpp file
void batchformat::readBatchformat() 
{
    ifstream batchFile; 
    //CODE HERE
    line = batchformat::readLinee(batchFile);

}


string batchformat::readLinee(ifstream batchFile)
{
    string thisLine;
    //CODE HERE
    return thisLine;
}
4

3 回答 3

13

问题是:

string readLinee(ifstream batchFile);

这会尝试按值传递流的副本;但流不可复制。您想通过引用传递:

string readLinee(ifstream & batchFile);
//                        ^
于 2013-07-15T13:21:20.710 回答
2
string batchformat::readLinee(ifstream batchFile)

正在尝试复制 ifstream 以 ref 代替

string batchformat::readLinee(ifstream& batchFile)
于 2013-07-15T13:21:37.013 回答
1

您的错误是您不能按值传递 ifstream :

string readLinee(ifstream batchFile);

通过 ref 传递它:

string readLinee(ifstream& batchFile);

我建议您更改方法中的 lign readBatchformat

void batchformat::readBatchformat() 
{
    ifstream batchFile; 
    //CODE HERE
    line = this->readLinee(batchFile);
    //      ^^^^^^
}

我认为它更具可读性。

于 2013-07-15T13:21:29.423 回答