In the general case, you do this either by explicitly calling the operator = for a base class subobject, or using the copy and exchange idiom, if available:
//explicit call to base operator= Derived& operator=(const Derived& rhs) { Base::operator=(rhs); // derivedInt = rhs.derivedInt; return *this; } //or copy&swap: Derived& operator=(const Derived& rhs) { Derived tmp(rhs); //copy tmp.swap(*this); return *this; } void swap(Derived& other) { Base::swap(other); std::swap(derivedInt,other.derivedInt); }
Update: since your base class is not intended for copying, your derived class also should not be assigned for copying. There are some cases where classes contain non-copyable parts, but are perfectly copyable. In those cases, the uncomplicated part is that which does not directly affect the state of class objects, for example. unique identificator. Then these parts will usually not be changed during the appointment. However, in those cases the parts not subject to copying should not be kept by inheritance, but rather by aggregation.
It is briefly said: Iheritance means the relationship "is-A". Your database cannot be copied. Your derivative is the base. Therefore, your Derived cannot be copied.
source share