C++?????????????y??
???????????? ???????[ 2012/10/19 10:50:52 ] ????????
????????C++?????????????????????????????????????????塣???????????????????????????????????????????????????????????й?????????????????????ν?????????????????????
????????????????????Boost??????C++??????????VS2005??????????Win32????
??????????????
#include "stdafx.h"
#include <string>
#include <iostream>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
using namespace std;
using namespace boost;
class CCycleRef
{
public:
~CCycleRef()
{
cout <<"destroying CCycleRef"<<endl;
}
public:
shared_ptr<CCycleRef> selfRef;
};
void CycleRefTest()
{
shared_ptr<CCycleRef> cyclRef(new CCycleRef());
cyclRef->selfRef = cyclRef;
cout<<"reference count:"<<cyclRef.use_count()<<endl;
}
int _tmain(int argc?? _TCHAR* argv[])
{
CycleRefTest();
return 0;
}
???????н????
????reference count:2
??????????CCycleRef????????????
?????????CCycleRef?????????????????ü??????????£?????????
??????????y??
????????weak_ptr????????????????????????weak_ptr??????????ü?????
???????CCycleRef??
class CCycleRef
{
public:
~CCycleRef()
{
cout <<"destroying CCycleRef"<<endl;
}
public:
weak_ptr<CCycleRef> selfRef;
};
???????н??
????reference count:1
????destroying CCycleRef
??????????CCycleRef???????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11