The renren6250 statement is comprehensive.
The use of delete or delete [] for arrays of simple data types such as int and char is exactly the same, and delete [] must be used for arrays of class instances;
C ++ casual Delete void *
After using C ++ for so long, I found that C ++ is the most complex language in all languages. The path to C ++ is hard .....
Delete void *
This operation will not be problematic for some simple built-in types of the system. However, if the object pointed to by void * is to be released in the destructor, memory will be lost during this creation,Because it does not execute destructorFor example:
Class centity
{
Public:
Centity (char flag );
~ Centity ();
PRIVATE:
Void * m_data;
Char m_flag;
};
Centity: centity (char flag)
{
M_flag = flag;
Cout <"constructing entity" <m_flag <Endl;
M_data = new char [100];
}
Centity ::~ Centity ()
{
Cout <"destructing entity" <m_flag <Endl;
Delete [] m_data;
}
There is no problem with the above class, but refer to the following calls:
Int main (INT argc, char * argv [])
{
Centity * A = new centity ('A ');
Delete;
Void * B = new centity ('B ');
Delete B;
Return 0;
}
The output is constructing Entity.
Destructing entity
Constructing entity B
It can be seen that the memory pointed to by m_data is not released and the Destructor is not executed during Delete B.
I don't know if I have collected it online, right?