智能指针 (四)
cout << "ref count of bptr: " << bptr.use_count() << endl;
cout << "ref count of aptr: " << waptr.use_count() << endl;
cout << "end" << endl;
}
int main()
{
test();
cout << "after test" << endl;
}
#include
#include
#include
using namespace std;
using namespace boost;
class B;
class A {
public:
~A() {
cout << "ref count of B: " << bptr.use_count() << endl;
cout << "deconstruct A" << endl;
}
shared_ptr bptr;
};
class B {
public:
~B() {
cout << "ref count of A: " << aptr.use_count() << endl;
cout << "deconstruct B" << endl;
}
weak_ptr aptr;
};
void test()
{
cout << "begin" << endl;
shared_ptr aptr(new A);
shared_ptr bptr(new B);