Creating array of objects on the stack and heap

前端 未结 5 1302
慢半拍i
慢半拍i 2020-12-01 07:12

Consider the following code:

class myarray
{
    int i;

    public:
            myarray(int a) : i(a){ }

}

How can you create an array of

5条回答
  •  孤独总比滥情好
    2020-12-01 07:22

    If you create an array of objects of class myarray ( either on stack or on heap) you would have to define a default constructor.

    There is no way to pass arguments to the constructor when creating an array of objects.

提交回复
热议问题