#include #include struct Foo { Foo() { std::cout << "Foo constructor" << std::endl; } ~Foo() { std::cout << "Foo destructor" << std::endl; } int x; }; void bar(Foo& f) { std::cout << f.x << std::endl; } int main(int argc, char** argv) try { boost::shared_ptr ptr(new Foo); if ( ptr ) { std::cout << "test the boolean context" << std::endl; } ptr->x = 1024; // std::cout << "test the arrow operator" << std::endl; bar(*ptr); // std::cout << "test the dereference operator" << std::endl; std::cout << "use_count " << ptr.use_count() << std::endl; { boost::shared_ptr ptr2 = ptr; boost::shared_ptr ptr3 = ptr; std::cout << "use_count " << ptr.use_count() << std::endl; } std::cout << "use_count " << ptr.use_count() << std::endl; return 0; } catch (std::bad_alloc e) { std::cerr << "memory allocation failure in main\n"; return 1; }