?? usercount.cpp
字號:
#include "usercount.h"
namespace mylib{
Usecount::Usecount():ref( new int(1) ){}
Usecount::Usecount(const Usecount& use)
{
++*ref;
}
bool Usecount::MakeOnly()//確保引用計數為一,寫拷貝支持使用
{
if(*ref == 1)
return false;
--*ref;
ref=new int(1);
return true;
}
bool Usecount::ReAttach(const Usecount& u)
{
++*u.ref;//最后總要加一,先加后可以免做自賦值判斷
if(--*ref ==0)
{ delete ref;
ref=u.ref;
return true;
}
ref=u.ref;
return false;
}
Usecount::~Usecount()
{
if(--*ref == 0)
{
delete ref;
}
ref=0;
}
}//end of mylib
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -