c++类的成员变量的存储位置?

浏览:34日期:2023-05-26

问题描述

问题解答

回答1:

Test * test_ptr = new Test(); 分配在堆上Test test; 在栈上

回答2:

Test *ptr = new Test;Test::array在堆上, ptr本身在栈上...

回答3:

要看类实例化在哪上

回答4:

都15年了该用c++11了智能指针更安全

//分配在堆上,多了不会爆栈,当然也不能大的太离谱了auto test_ptr = shared_ptr<Test>(new Test()); //在栈上,多了会爆栈的Test test;

相关文章: