/usr/include/c++/4.4/bits/ios_base.h: In member function ‘std::basic_ios >& std::basic_ios >::operator=(const std::basic_ios >&)’:
/usr/include/c++/4.4/bits/ios_base.h:793: error: ‘std::ios_base& std::ios_base::operator=(const std::ios_base&)开发者_JAVA百科’ is private /usr/include/c++/4.4/iosfwd:47: error: within this context /usr/include/c++/4.4/iosfwd: In member function ‘std::basic_ostream >& std::basic_ostream >::operator=(const std::basic_ostream >&)’: /usr/include/c++/4.4/iosfwd:56: note: synthesized method ‘std::basic_ios >& std::basic_ios >::operator=(const std::basic_ios >&)’ first required here /usr/include/c++/4.4/iosfwd: In member function ‘std::basic_ofstream >& std::basic_ofstream >::operator=(const std::basic_ofstream >&)’: /usr/include/c++/4.4/iosfwd:84: note: synthesized method ‘std::basic_ostream >& std::basic_ostream >::operator=(const std::basic_ostream >&)’ first required here /usr/include/c++/4.4/streambuf: In member function ‘std::basic_filebuf >& std::basic_filebuf >::operator=(const std::basic_filebuf >&)’: /usr/include/c++/4.4/streambuf:778: error: ‘std::basic_streambuf<_CharT, _Traits>& std::basic_streambuf<_CharT, _Traits>::operator=(const std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char, _Traits = std::char_traits]’ is private /usr/include/c++/4.4/iosfwd:78: error: within this context /usr/include/c++/4.4/iosfwd: In member function ‘std::basic_ofstream >& std::basic_ofstream >::operator=(const std::basic_ofstream >&)’: /usr/include/c++/4.4/iosfwd:84: note: synthesized method ‘std::basic_filebuf >& std::basic_filebuf >::operator=(const std::basic_filebuf >&)’ first required here
anyone has any idea what is this error about?
Update: it comes from the following line:
ofstream myOutStream = ofstream(myCurrentLogName.c_str(), ios::app);
You are trying to copy or assign a stream (descendant of std::istream
or std::ostream
). Streams, however, cannot be copied or assigned.
Edit
Change your code to:
std::ofstream myOutStream(myCurrentLogName.c_str(), std::ios::app);
That is the first line of a two-line error message. The first line gives the location of the private/protected member you're trying to access, and the second line gives the location of the attempt to access it. The full message will look something like
header.h:53: error: `thing` is private
source.cpp:99: error: within this context
The second line will tell you where to look for the error.
Update
That was the answer to the original question. Now we've seen the full error message and the code causing it, sbi has the answer.
精彩评论