C++安全删除指针SAFE_DELETE宏

C++安全删除指针SAFE_DELETE宏

在directx工具中有这样几个定义:

#define SAFE_DELETE(p)       { if(p) { delete (p);     (p)=NULL; } }
#define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p);   (p)=NULL; } }
#define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=NULL; } }

#define :相当于代码替换,而不是函数定义;

posted @ 2021-11-05 16:32  余生以学  阅读(867)  评论(0编辑  收藏  举报