C ++: constructor initialization list for an array?

I have a basic question. I have a class with a data member: double _mydata[N] . (N is the template parameter). What is the syntax for initializing this data to zero using the constructor initialization list? Is _mydata({0}) OK according to the C ++ standard (and therefore for all compilers)?

Many thanks.

+7
source share
1 answer

No, before C ++ 11 you only need to do this by default - initialize each element of the array:

 : _mydata() 

The way you wrote it will not work.

With C ++ 11, it is recommended to use a uniform initialization syntax:

 : _mydata { } 

And in this way you can put things in an array that you could not have before:

 : _mydata { 1, 2, 3 } 
+12
source

All Articles