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

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

    Since you're using new, you're allocating your object on the heap. Consequently, every members of the Test pointed by t are on the heap too.

提交回复
热议问题