#include #include struct testobj { testobj() { printf("default[%p]\n", this); } testobj(const testobj& x) { printf("copied[%p] from %p\n", this, &x); } ~testobj() { printf("destroyed[%p]\n", this); } void method() { printf("method[%p]\n", this); } }; typedef boost::shared_ptr testobj_ptr; void test(testobj_ptr x) { x->method(); } int main(int,char**) { testobj x; if (1) { printf("{\n"); test(testobj_ptr(testobj_ptr(), &x)); printf("}\n"); } if (1) { testobj_ptr p= testobj_ptr(new testobj()); printf("{\n"); test(testobj_ptr(testobj_ptr(), &x)); printf("}\n"); } x.method(); printf("done\n"); return 0; }