#include <cstdlib>
//多个 shared_ptr 指向同一个 内存块
//修改任何一个内存块,都是在修改多有的 shared_ptr
#include <iostream>
using namespace std;
#include <boost/shared_ptr.hpp>
using namespace boost;
#include <cassert>
class A
{
shared_ptr<int> no_;
public:
A(shared_ptr<int> p):no_(p){}
void SetValue(int n){*no_ = n;}
int GetValue()const{return *no_;}
};
class B
{
shared_ptr<int> no_;
public:
B(shared_ptr<int> p):no_(p){}
void SetValue(int n){*no_ = n;}
int GetValue()const{return *no_;}
};
void Do()
{
shared_ptr<int> Temp(new int(10));
A a(Temp);
B b(Temp);
cout<<"a 的值为 : "<<a.GetValue()<<endl;
a.SetValue(20);
cout<<"b 的值为 : "<<b.GetValue()<<endl;
assert(b.GetValue() == 20);
}
int main(int argc, char *argv[])
{
Do();
system("PAUSE");
return EXIT_SUCCESS;
}