----- Original Message -----
From: "Jonathan Brownell"
Essentially what I need is a const data member that is protected as a const except during House::operator =(const House&), at which point the entire class is replaced. Am I just out of luck? If so, this makes const class data members pretty useless in many cases, because similar situations to this have arisen quite a few times for me.
You could use Johan Ericsson idea:
House& House::operator =(const House& source) { House temp(source); Swap(temp); return *this; }
and then use const_cast in swap:
void swap(const House& h)
{
int temp = h.m_rooms;
override_const_assign(h.m_rooms, m_rooms); // h.m_rooms = m.rooms
override_const_assign(m_rooms, temp); // m_rooms = temp;
}
template<class T>
void override_const_assign(const T& lhs, const T& rhs)
{
lhs2 = const_cast