c ++ object-oriented programming notes four

1. Understand the heap space and stack space

Create objects of different ways.

2.local object and static local object life cycle

Lifecycle 3.heap object of attention explicitly released.

4. new allocate memory recall ctor

Complex *pc;




void* mem = operator new(sizeof(Complex));
pc = static_cast<Compex*>(mem);
pc->Complex::Complex(1,2);

 

 

delete call first and then release the memory dtor

String* ps = new String("Hello");
...
delete PS;


String::~String(ps);
operator delete(ps);

Detailed in c ++ memory management and allocation (todo notes)

 

 

Published 44 original articles · won praise 5 · Views 1394

Guess you like

Origin blog.csdn.net/qq_33776188/article/details/104662781