class Person
{
public:
string name;
};
int main()
{
typedef Person FinalType; //起个别名
void *pointer = malloc(sizeof(FinalType)); //分配一块内存
FinalType* typeConstructor = new (pointer) FinalType(); //在已分配的内存上,创建对象;new (pointer) FinalType; 也可以
typeConstructor->name = "xiaoming";
if ((void*)typeConstructor == (void*)pointer) //两个指针指向的是同一个内存
{
printf("same address");
}
参考:https://www.bilibili.com/read/cv14906544/