我在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;
}
答案 0 :(得分:12)
问题是:
string readLinee(ifstream batchFile);
这会尝试按值传递流的副本;但流不可复制。您希望通过引用传递:
string readLinee(ifstream & batchFile);
// ^
答案 1 :(得分:2)
string batchformat::readLinee(ifstream batchFile)
正在尝试复制ifstream 取而代之的是
string batchformat::readLinee(ifstream& batchFile)
答案 2 :(得分:1)
您的错误是您无法按值传递ifstream:
string readLinee(ifstream batchFile);
通过ref传递它:
string readLinee(ifstream& batchFile);
我建议你改变readBatchformat
方法中的lign:
void batchformat::readBatchformat()
{
ifstream batchFile;
//CODE HERE
line = this->readLinee(batchFile);
// ^^^^^^
}
我认为它更具可读性。