operator=() is private in ios_base. Using private inheritance of ios_base the program below fails in the constructor when '=' is used (but not during memory initialization). I don't understand why assignment is prohibited.
art Program 1 fails # include <ostream> using namespace std; class thing : private ios_base { ostream& xo; public: thing(ostream& y) : xo(y) { xo = y; } }; gcc.3.4.4 messaging x.cpp: In member function `std::basic_ios<char, std::char_traits<char> >& std::basic_ios<char, std::char_traits<char> >::operator=(const std::basic_ios<char, std::char_traits<char> >&)': /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/ios_base.h:784: error: `std::ios_base& std::ios_base::operator=(const std::ios_base&)' is private x.cpp:9: error: within this context Program 2 succeeds # include <ostream> using namespace std; class thing : private ios_base { ostream* yo; public: thing(ostream& y) { yo = &y; } thing(ostream y) { yo = &y; } }; Program 4 fails # include <ostream> using namespace std; class thing : private ios_base { ios_base& xo; public: thing(ios_base& y) { xo = y; } }; gcc.3.4.4 messaging x.cpp: In constructor `thing::thing(std::ios_base&)': x.cpp:9: error: uninitialized reference member `thing::xo' /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/ios_base.h:784: error: `std::ios_base& std::ios_base::operator=(const std::ios_base&)' is private x.cpp:9: error: within this context