Why one would want to explicitly clear the a vector member variable (of on in a dtor (please see the code below). what are the benefits of clearing the vector, even though i
In your second example there's no reason to set p_
to null whatsoever, specifically because it is done in the destructor, meaning that the lifetime of p_
will end immediately after that.
Moreover, there's no point in comparing p_
to null before calling delete
, since delete
expression performs this check internally. In your specific artificial example, the destructor should simply contain delete p_
and noting else. No if
, no setting p_
to null.