Dea*_*tor 3 c++ null destructor explicit class
可能重复:
是否值得在析构函数中设置指向NULL的指针?
NULL
在析构函数中设置指针(分配堆内存)是没有意义的吗?
class SampleClass
{
public:
SampleClass( int Init = 0 )
{
Value = new int( Init );
}
~SampleClass( void )
{
delete Value;
Value = NULL; // Is this pointless?
}
int *Value;
};
Run Code Online (Sandbox Code Playgroud)
关于课程的主题,我explicit
什么时候应该使用关键字?
是.这是毫无意义的,因为对象是在被破坏的过程中.一旦它被销毁,就无法到达指针.