c++effective 2

#include<string>
class Bitmap {};
class Widget {
	Widget& operator=(const Widget& rhs);
private:
	Bitmap* pb;
};
Widget& Widget::operator=(const Widget& rhs)
{	
	//if (this == &rhs) return *this;
	//delete pb;
	//pb = new Bitmap(*rhs.pb);
	Bitmap* pOrig = pb;
	pb = new Bitmap(*rhs.pb);
	delete pOrig;
	return *this;
}
void logCall(const std::string& funcName);
class Date{};
class Customer
{
public:
	Customer();
	~Customer();
	Customer(const Customer& rhs);
	Customer& operator=(const Customer& rhs);
private:
	std::string name;
	Date lasttransaction;
};

Customer::Customer()
{
}

Customer::~Customer()
{
}
Customer::Customer(const Customer& rhs):name(rhs.name)
{
	logCall("Customer copy constructor");
}
Customer& Customer::operator=(const Customer& rhs)
{
	// TODO: 在此处插入 return 语句
	logCall("Custoer copy assigment operator");
	name = rhs.name;
	return *this;
}
class PriorityCustomer :public Customer {
public:
	PriorityCustomer& operator=(const PriorityCustomer& rhs);
	PriorityCustomer(const PriorityCustomer& rhs);
private:
	int priority;

};

int main()
{	//11:provision Handle Asssignment to in operator-
	Widget wid;
	//12.provision copy all part of an object

	//13 provision Use objects to manege resources;
	//14 provision copying behavior in resource managing classes
	//17 provision 
	return 0;
}
class Investment {};
Investment* createInvestment();
void f()
{
	Investment* pInv = createInvestment();
	delete pInv;
	//std::auto_ptr<Investment>pInv(createInvestment())
	//std::trl::shared_ptr<Investmen> pInv(createInvestment())
}

PriorityCustomer& PriorityCustomer::operator=(const PriorityCustomer& rhs)
{
	// TODO: 在此处插入 return 语句
	logCall("PriorityCustomer copy assignment");
	Customer::operator=(rhs);
	priority = rhs.priority;
	return *this;
}

PriorityCustomer::PriorityCustomer(const PriorityCustomer& rhs):priority(rhs.priority),Customer(rhs)
{
	logCall("PriorityCusomer copy constructor");

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值