Jessie-Cheng1 / xuexi

0 stars 0 forks source link

new和delete #102

Open Jessie-Cheng1 opened 2 years ago

Jessie-Cheng1 commented 2 years ago

new

image new 先分配内存,再调用构造函数 Complex* pc = new Complex(1,2)定义一个指向Complex的指针 编译器转换为3步

Jessie-Cheng1 commented 2 years ago

delete

image

Jessie-Cheng1 commented 2 years ago

分配内存图:

image

array new 和array delete(new[] 和delete[])

原则: 搭配使用,有中括号的new搭配有中括号的delete image