应该这么用auto_ptr
#include <memory>
auto_ptr<TestClass> ap(new TestClass);//注意这里是调用的构造函数,不是=重载符
ap->Func();
或者
TestClass* p = new TestClass;
auto_ptr<TestClass) ap(p);
ap->Func();
 
千万不能这么用:
auto_ptr<TestClass> ap = new TestClass;//注意这里是=重载符
ap->Func()
 
个中原因,主要是要完成由new TestClassauto_ptr<TestClass>的转换,auto_ptr没有这样的直接=重载,它误用auto_ptr_ref来完成这个转换,会造成错误。auto_ptr_ref设计的本意本不是这个。