The way to apply for pointers in C is usually NEW and DELETE. However, there is a powerful template class in standard C to automatically help you release memory automatically when you are not used. Let's take a look at the usage.
Use
Std :: auto_ptr
Method
Std :: auto_ptr
m_example.reset (new myclass ());
Using the law three (assignment operation of the pointer)
Std :: auto_ptr
Std :: auto_ptr
m_example2 = m_example1;
Then C will reclaim the memory to the m_example, so that the value of the m_example is NULL, so in C , it should be absolutely avoided in the container. Avoid the following code
Vector
When using the algorithm to operate, you can't avoid the implementation of the elements in the container in the STL, so that multiple elements in the container are set null, and this is not what we want to see.