Code:
auto_ptr<B> ptr(new D);
Note : passing atuo_ptrs are problematic because of the ownership
of the pointer when copied.

After calling the function, do the following:

Code:
bar(ptr);

if (ptr.get() == NULL)  
{
   cout << "null\n"; 
}
Also, add a destructor to the classes, printing out a message, and see
when the pointer gets deleted.