学习笔记(01):<3>华为工程师 ,带你实战C++(2018版)-06内存的层次化管理-实现与声明的分离...

立即学习:https://edu.csdn.net/course/play/9122/189931

C++内存管理

C语言内存

申请:

从外到内

释放:

从内到外

C++中

#include <iostrean>
using namespace std;

class Stu
{
public:
    Stu()
    {
        cout<<"Stu()"<<endl;
        name = new char[1023];
        age = 18;
            
    }
    ~Stu()
    {
        cout<<"~Stu()"<<endl;
        delete []name;
    }
private:
    char *name;
    int age;    
}

int main()
{
    Stu *s = new Stu();
    delete s;
}

猜你喜欢

转载自blog.csdn.net/ZOROE123/article/details/97689004