Determine array size in constructor initializer

前端 未结 12 2355
失恋的感觉
失恋的感觉 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:48

    Two options:

    Use std::vector. This allows easy re-sizing of the array.
    Use std::tr1::array. This has a static size.

    Both can be correctly initialized in the constructors initializer list.

提交回复
热议问题