Does this type of memory get allocated on the heap or the stack?

前端 未结 5 1057
北荒
北荒 2020-11-30 15:23

In the context of C++ (not that it matters):

class Foo{
    private:
        int x[100];
    public:
        Foo();
}

What I\'ve learnt tel

5条回答
  •  一向
    一向 (楼主)
    2020-11-30 15:51

    An object of type Foo takes the size of 100 ints stored in sequence. If you create it on the stack, you will be getting it all on the stack. If you do it with new, it'll be on the heap as part of the object.

    This is part of the language specification, I'm not sure what your question is.

提交回复
热议问题