离开作用域时清理资源C++代码
如果你不使用智能指针,这个方法将对你有帮助 // 离开作用域时清理p YourClass* p = new YourClass ScopeGuard sg = MakeGuardObject(p); // 离开作用域时清理p数组 YourClass* p = new YourClass[100]; ScopeGuard sg = MakeGuardArray(p); // 离开作用域时调用mutex对象的Lock方法 ScopeGuard sg = MakeGuardMethod(mutex, &Mutex::Lock);
下载地址
用户评论