ifstream通过引用返回对象

时间:2013-11-27 07:54:28

标签: c++

//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 
}

嗨,我有上课结构

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

1 个答案:

答案 0 :(得分:5)

您正在尝试复制构造流,这是无法完成的。您错过了一个&

ifstream& ifs1 = storeManager.getDataWriterStream();
//------^