Are data members allocated in the same memory space as their objects in C++?

前端 未结 6 1071
野的像风
野的像风 2020-12-03 09:09

Say I\'ve got a class like this:

class Test
{
  int x;
  SomeClass s;
}

And I instantiate it like this:

Test* t = new Test;         


        
6条回答
  •  情歌与酒
    2020-12-03 09:24

    t is on the stack. The object at *t is on the heap. It contains an int and a SomeClass object next to each other in a unit.

提交回复
热议问题