class Customer {
public:
...
Customer(const Customer& rhs);
Customer& operator=(const Customer& rhs);
...
priavte:
std::string name;
};
class PriorityCustomer: public Customer {
public:
...
PriorityCustomer(const PriorityCustomer& rhs);
PriorityCustomer& operator=(const PriorityCustomer& rhs);
...
private:
int priority;
};
The data members it inherits from Customer, and those data members are not being copied at all. The Customer part of the PriorityCustomer object will be initialized by the constructor taking no arguments-by the defaule constructor.
PriorityCustomer::PriorityCustomer(const PriorityCustomer& rhs): priority(rhs.priority) {}
the right way
PriorityCustomer::PriorityCustomer(const PriorityCustomer& rhs): Customer(rhs), priority(rhs.priority) {}
PriorityCustomer&
PriorityCustomer::operator=(const PriorityCustomer& rhs) {
Customer::operator=(rhs);
priority = rhs.priority;
return *this;
};