开发者

creating a class within another class memory allocation

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜