//Effective C++ Item12
#include<iostream>
#include<cstring>
using namespace std;
class Customer{
public:
//Customer(const Customer& rhs);
Customer& operator=(const Customer& rhs){
name = rhs.name;
return *this;
}
private:
std::string name;
};
class PriorityCustomer :public Customer{
public:
PriorityCustomer(const PriorityCustomer& rhs) :priority(rhs.priority){
};
//当你编写一个copying函数,请确保(1)赋值所有local成员变量(2)调用所有base class内的适当的copying函数
PriorityCustomer& operator=(const PriorityCustomer& rhs){
//对base class成分进行赋值动作
Customer::operator=(rhs);
priority = rhs.priority;
return *this;
};
private:
int priority;
};
Effective C++ Item12 Note
最新推荐文章于 2023-04-24 00:51:28 发布