Determine array size in constructor initializer

前端 未结 12 2412
失恋的感觉
失恋的感觉 2020-12-08 21:10

In the code below I would like array to be defined as an array of size x when the Class constructor is called. How can I do that?

class Class
{
public:
  int         


        
12条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-08 21:41

    Declare your array as a pointer. You can initialize it in the initializer list later through through new.

    Better to use vector for unknown size.

    You might want to look at this question as well on variable length arrays.

提交回复
热议问题