#include <iostream>
using namespace std;
#define SAFETY_CHECK(ptr) \
{ \
if (ptr == nullptr) \
{ \
cout << "Reference is NULL" << endl; \
return false; \
} \
else \
cout << "Reference is not NULL" << endl; \
return true; \
} \
template<typename T>
bool IsSafe(T* ptr) { SAFETY_CHECK(ptr); }
#define SAFE_DELETE(ptr) if(IsSafe(ptr)) delete ptr
class Test
{
public:
Test()
{
cout << "생성자 호출" << endl;
}
~Test()
{
cout << "소멸자 호출" << endl;
}
};
int main()
{
Test* p = new Test();
SAFE_DELETE(p);
return 0;
}