C++複製對象時勿忘每一部分,複製對象勿忘
確保兩點: 1 複製所有的成員變數 2 調用所有基類的copy函數
class Customer{public:explicit Customer(const tstring _name,const tstring _lastTransaction):m_sName(_name), m_sLastTransaction(_lastTransaction){OutputDebugString(_T("Customer construct \n"));}virtual ~Customer(){OutputDebugString(_T("Customer deconstruct \n"));}Customer(const Customer& customer) : m_sName(customer.m_sName){OutputDebugString(_T("Customer copy construct \n"));}Customer& operator=(const Customer& customer){m_sName = customer.m_sName;OutputDebugString(_T("Customer operater \n"));return *this;}private:tstring m_sName;tstring m_sLastTransaction;};class PriorityCustomer: public Customer{public:explicit PriorityCustomer(const tstring name,const tstring lastTime,int nPriority):m_nPriority(nPriority), Customer(name, lastTime){OutputDebugString(_T("PriorityCustomer construct \n"));}PriorityCustomer(const PriorityCustomer& rhs) :m_nPriority(rhs.m_nPriority),Customer(rhs){OutputDebugString(_T("PriorityCustomer copy construct\n"));}PriorityCustomer& operator=(const PriorityCustomer rhs){OutputDebugString(_T("PriorityCustomer operater \n"));m_nPriority = rhs.m_nPriority;Customer::operator=(rhs);return *this;}virtual ~PriorityCustomer(){OutputDebugString(_T("PriorityCustomer deconstruct \n"));}private:int m_nPriority;};