How can I initialize normal array member variable in initializer list?

后端 未结 2 656
无人及你
无人及你 2020-12-12 01:32

I would like to do the following:

class MyClass {
    public:
        MyClass() : arr({1,2,3,4,5,6,7,8}) {}

    private:
        uint32_t arr[8];
};
         


        
相关标签:
2条回答
  • 2020-12-12 02:08

    Works perfectly on GCC 4.5.2 with -std=gnu++0x. I get a warning and a freeze with -std=c++98.

    0 讨论(0)
  • 2020-12-12 02:30

    Your syntax is correct. Alternatively, you can say arr{1,2,3,...}.

    Most likely is that your compiler just doesn't support this construction yet. GCC 4.4.3 and 4.6.1 both do (with -std=c++0x).

    0 讨论(0)
提交回复
热议问题