This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
operator=() issue
- From: Arthur Schwarz <aschwarz1309 at verizon dot net>
- To: gcc at gcc dot gnu dot org
- Date: Fri, 10 Apr 2009 16:21:52 -0700 (PDT)
- Subject: operator=() issue
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