#include <iostream>
#include <fstream>
#include <list>
usingnamespace std;
class X
{
public:
ofstream out ;
} ;
int main()
{
list<X> xz ;
list<X>::iterator xi ;
X x ;
x.out.open( "./xyz1.txt" ) ;
xz.push_back( x ) ;
x.out.open( "./xyz2.txt" ) ;
xz.push_back( x ) ;
for( xi = xz.begin() ; xi != xz.end() ; ++xi )
{
(*xi).out << "Hello World" << endl ;
}
return 0;
}
3 error messages are
/usr/include/c++/4.2.1/bits/basic_ios.tcc:192: error: base class 'std::ios_base' has private copy constructor
extern template class basic_ios<char>;
^
/usr/include/c++/4.2.1/bits/ostream.tcc:326: error: no matching constructor for initialization of 'basic_ios<char, std::char_traits<char> >'
extern template class basic_ostream<char>;
^~~~~~~~~~~~~
/usr/include/c++/4.2.1/bits/fstream.tcc:892: error: base class 'basic_streambuf<char, std::char_traits<char> >' has private copy constructor
extern template class basic_filebuf<char>;
^
The C++ streams aren't copyable, but they are movable (since C++11). The following compiles with clang++ and LLVM libc++ standard library and runs on my linux just fine: