N
Nephi Immortal
I am surprised to find out why the destructor function does not test
pointer before memory is deleted.
struct Object
{
Object( int n ) : ptr( new char[ n ] )
{
}
~Object()
{
// comment if condition
// if( ptr != NULL )
delete [] ptr;
}
char *ptr;
};
Any C++ books say you must always include if condition to test
pointer if it is not zero before memory is allowed to be deallocated.
I found out that delete function already has if condition. The
delete function returns zero without deallocating memory if pointer is
zero.
pointer before memory is deleted.
struct Object
{
Object( int n ) : ptr( new char[ n ] )
{
}
~Object()
{
// comment if condition
// if( ptr != NULL )
delete [] ptr;
}
char *ptr;
};
Any C++ books say you must always include if condition to test
pointer if it is not zero before memory is allowed to be deallocated.
I found out that delete function already has if condition. The
delete function returns zero without deallocating memory if pointer is
zero.