开发者

creating a class within another class memory allocation

开发者 https://www.devze.com 2023-02-02 03:36 出处:网络
If I have a few classes, say one is a base class and it is created inside another class, will it be located o开发者_高级运维n the stack or heap if the \"outside\" class is created with the new operato

If I have a few classes, say one is a base class and it is created inside another class, will it be located o开发者_高级运维n the stack or heap if the "outside" class is created with the new operator but the class created inside of it isn't. For example:

class baseclass
{
   //code here
};

class outside
{
     baseclass mybase;
     //more code
};

int main()
{
    outside *myclass;
    myclass = new outside;
}

Is mybase allocated on the heap as well? Thanks!


Yes. That's correct. It does not require an additional new or delete for it though.


Your outside and baseclass are created at the same memory area.

0

精彩评论

暂无评论...
验证码 换一张
取 消