c++类的成员变量的存储位置?
ringa_lee
ringa_lee 2017-04-17 13:11:15
0
4
506
ringa_lee
ringa_lee

ringa_lee

reply all(4)
大家讲道理

Test * test_ptr = new Test(); allocated on the heap
Test test; on the stack

迷茫

Test *ptr = new Test;
Test::array is on the heap, ptr itself is on the stack...

巴扎黑

It depends on where the class is instantiated

洪涛

It’s been 15 years and it’s time to use c++11
Smart pointers are safer

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

//在栈上,多了会爆栈的
Test test; 
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template