//StoreManager.cpp
ifstream& StoreManager::getDataReaderStream()
{
m_dataReader.open(m_dataReaderFileName.c_str(), ios::in | ios::binary);
return m_dataReader;
}
//multithread.cpp
void runThread (void *lpData)
{
ifstream ifs1 = storeManager.getDataWriterStream();
//other code
}
嗨,我有以上类(class)结构
ifstream ifs1 = storeManager.getDataWriterStream();
我得到这个,请帮助我没有得到这个,
/usr/include/c++/4.6/fstream: In copy constructor âstd::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)â:
/usr/include/c++/4.6/fstream:420:11: note: synthesized method âstd::basic_ios<char>::basic_ios(const std::basic_ios<char>&)â first required here
/usr/include/c++/4.6/streambuf: In copy constructor âstd::basic_filebuf<char>::basic_filebuf(const std::basic_filebuf<char>&)â:
/usr/include/c++/4.6/streambuf:782:7: error: âstd::basic_streambuf<_CharT, _Traits>::basic_streambuf(const __streambuf_type&) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_streambuf<_CharT, _Traits>::__streambuf_type = std::basic_streambuf<char>]â is private
/usr/include/c++/4.6/fstream:69:11: error: within this context
/usr/include/c++/4.6/fstream: In copy constructor âstd::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)â:
/usr/include/c++/4.6/fstream:420:11: note: synthesized method âstd::basic_filebuf<char>::basic_filebuf(const std::basic_filebuf<char>&)â first required here
multithread.cpp: In member function âvirtual void Multithread::runThread(void*)â:
multithread.cpp:33:57: note: synthesized method âstd::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)â first required here
最佳答案
您正在尝试复制-构造流,但无法完成。您错过了一个&
:
ifstream& ifs1 = storeManager.getDataWriterStream();
//------^
关于c++ - ifstream通过引用返回对象,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20236765/