如何用auto_ptr作为函数的参数进行传递

auto_ptr跟指针的原理是同样的,只不过在使用会自动释放内存。可是在函数中做为auto_ptr参数使用时,必定要注意控制权的转移问题。安全 void testptrAddNumber(MCMDTLog* mmcLog) { mmcLog->addNumber(); } void func(auto_ptr<int>& ap) { cout << *ap << endl; }
相关文章
相关标签/搜索