C++ : constructor initialization list for an array?

后端 未结 1 445
走了就别回头了
走了就别回头了 2021-01-02 17:18

I have a basic question. I have a class with a data member : double _mydata[N]. (N is a template parameter). What is the syntax to initialize these data to zero

相关标签:
1条回答
  • 2021-01-02 17:45

    No, prior to C++11 you need to do just this to default-initialise each element of the array:

    : _mydata()
    

    The way you have it written won't work.

    With C++11 it is more recommended use uniform initialisation syntax:

    : _mydata { }
    

    And that way you can actually put things into the array which you couldn't before:

    : _mydata { 1, 2, 3 }
    
    0 讨论(0)
提交回复
热议问题