Does a type require a default constructor in order to declare an array of it?
问题 I noticed that when you declare an array, the default constructor must be needed. Is that right? Is there any exception? For example, struct Foo{ Foo(int i ) {} }; int main () { Foo f[5]; return 0; } The code above does not compile. 回答1: Other answers are all right but, for completeness: You could also use the array initialization syntax: Foo f[5] = {1,2,3,4,5}; This works if Foo's ctor is not explicit. If it was, you'd have to be.... explicit: Foo f[5] = {Foo(1), Foo(2), Foo(3), Foo(4), Foo