How do I declare an array of objects whose class has no default constructor?

后端 未结 13 1093
时光取名叫无心
时光取名叫无心 2020-11-30 06:25

If a class has only one constructor with one parameter, how to declare an array? I know that vector is recommended in this case. For example, if I have a class



        
13条回答
  •  一向
    一向 (楼主)
    2020-11-30 06:35

    In straight C, using int foo[10000] = {1}; will initialize the first array item to 1 and the remainder of the array to zero. Does C++ not auto-initialize unspecified array members, or does this require a default constructor?

提交回复
热议问题