#include <iostream>
#include <boost/shared_ptr.hpp>
using namespace std;
using namespace boost;
struct Melpon {
Melpon(const char* name) : name_(name) {}
~Melpon() {cout << name_ << " は死んだ。" << endl;}
void harahe() {cout << name_ << " ははらへ。" << endl;}
private:
const char* name_;
};
int main() {
shared_ptr<Melpon> sp(new Melpon("めるぽん"));
weak_ptr<Melpon> wp(sp);
sp->harahe();
if (shared_ptr<Melpon> p = wp.lock()) {
p->harahe();
}
sp.reset(); // ここで死亡
if (shared_ptr<Melpon> p = wp.lock()) {
p->harahe();
} else {
cout << "めるぽんは既に死んでる。" << endl;
}
return 0;
}