写了个示例代码:
#include <iostream>
using namespace std;
class Test
{
public:
Test(int num) {
m_num = num;
cout<<"Construtor: "<<num<<endl;
}
~Test() {
cout<<"Destructor"<<endl;
}
private:
int m_num;
};
int main()
{
char *pMem = new char[1000];
Test *pTest = new(pMem) Test(10);
// The following statement is equivalent to "delete pTest"
pTest->~Test(); // If there is no this statement,
// the destructor will not be called
// Try to comment it, and then run this program
delete [] pMem;