See my comment.
There are many ways to fix this. One is this:
void getMultiDataReaderStream(ifstream& ifs)
{
ifs.open(m_dataReaderFileName.c_str(), ios::in | ios::binary);
}
void
runThread(void *lpData)
{
ifstream ifs1;
getMultiDataReaderStream(ifs1);
// code for reading while EOF
ifs1.close();
}
Another is this:
(don't use this, this works, but it's sloppy)
ifstream* getMultiDataReaderStream()
{
ifstream* ifs = new ifstream(m_dataReaderFileName.c_str(), ios::in | ios::binary);
return ifs;
}
void
runThread(void *lpData)
{
ifstream* ifs1 = getMultiDataReaderStream();
// code for reading while EOF
ifs1->close();
delete ifs1;
}
And then with smart ptr:
shared_ptr<ifstream> getMultiDataReaderStream()
{
shared_ptr<ifstream> ifs = shared_ptr<ifstream>(new ifstream(m_dataReaderFileName.c_str(), ios::in | ios::binary));
return ifs;
}
void
runThread(void *lpData)
{
shared_ptr<ifstream> ifs1 = getMultiDataReaderStream();
// code for reading while EOF
ifs1->close();
}
I am sure there are other ways...