Home > Back-end >  C the STL template destructor
C the STL template destructor

Time:10-22

Today the STL source code analysis, internal a destroy function
The template & lt; The class T>
The inline void destroy (T * pointer)
{
Pointer - & gt; ~ (T);
}

When T is int, such as:
Int * PTR=new int.
Destroy (PTR);
So you can compile and direct PTR - & gt; ~ the int (); Just an error,
This is why ah, seek advice,

CodePudding user response:

The destructor is generally not directly call
The template & lt; The class T>
The inline void destroy (T * pointer)
{
Delete the pointer;
}

CodePudding user response:

The placement of new,
  • Related