#include <iostream>usingnamespacestd;
class Person
{
public:
Person()
{
cout << "构造函数" << endl;;
}
~Person()
{
cout << "析构函数" << endl;
}
};
int main()
{
int *pStart = newint[1024];
int *pEnd = pStart + 1024;
cout << static_cast<void*>(pStart) << " "
<< static_cast<void*>(pEnd) << endl;
Person * japanese = new Person;
cout << japanese << endl;
Person *chinese = new Person;
cout << chinese << endl;
//将Person类对象限定在指针p指向的区域内//限定区域分配内存,覆盖模式
Person * korean = new (pStart)Person;//korean 内存空间为起始地址为pStartcout << korean << endl;
//delete korean;//一般不需要delete,自动覆盖
Person *english = new (pStart +10)Person;//english内存空间起始地址为pStart +10*4cout << english << endl;
cin.get();
return0;
}