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

前端 未结 6 1086
野的像风
野的像风 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:45

    Since you've used new, it's all on the heap, stored [more or less] contiguously in t's memory area.

提交回复
热议问题