// weakPtrTest.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include "weak/weak_ptr.hpp"
class Test {
weak::weak_ptr_factory<Test> weak_ptr_factory_;
public:
Test() :weak_ptr_factory_(this)
{}
weak::weak_ptr<Test> get_weak_ptr() const {
return weak_ptr_factory_.get_weak_ptr();
}
};
int main()
{
Test* pTest = new Test();
auto weak_p = pTest->get_weak_ptr();
bool b = weak_p.expired();
if (pTest)
delete pTest;
bool b2 = weak_p.expired();
return 0;
}
weak_ptr 检测类对象是否存在
于 2022-09-29 14:06:02 首次发布