可能是重复问题:
在析构函数中将指针设置为NULL的作用是什么?
在析构函数中将分配堆内存的指针设置为NULL
是没有意义的吗?
class SampleClass
{
public:
SampleClass( int Init = 0 )
{
Value = new int( Init );
}
~SampleClass( void )
{
delete Value;
Value = NULL; // Is this pointless?
}
int *Value;
};
谈到类时,何时应该使用explicit
关键字?
explicit
的用法在 "What does the explicit keyword in C++ mean?" 中有解释。 - James McNellis