#include <vector>
struct X { X(int i) { x = i; }; int x; };
struct Y { int y; };
int main()
{
const int n = 4;
int k = 4;
X x1[n]; // compile error: no default constructor
X x2[n] = { 1, 2, 3, 4};
Y y1[n];
Y y2[k]; // compile error: k is non-const
X *xp = new X[k]; // compile error: no default constructor
Y *yp = new Y[k];
std::vector<X> xv(10); // compile error: no default constructor
std::vector<Y> yv(10);
delete [] yp;
return 0;
}
I2luY2x1ZGUgPHZlY3Rvcj4KCnN0cnVjdCBYIHsgWChpbnQgaSkgeyB4ID0gaTsgfTsgaW50IHg7IH07CnN0cnVjdCBZIHsgICAgICAgICAgICAgICAgICAgICAgaW50IHk7IH07CgppbnQgbWFpbigpCnsKICBjb25zdCBpbnQgbiA9IDQ7CiAgICAgICAgaW50IGsgPSA0OwoKICBYIHgxW25dOyAgICAgICAgICAgICAgICAvLyBjb21waWxlIGVycm9yOiBubyBkZWZhdWx0IGNvbnN0cnVjdG9yCiAgWCB4MltuXSA9IHsgMSwgMiwgMywgNH07CiAgWSB5MVtuXTsKICBZIHkyW2tdOyAgICAgICAgICAgICAgICAvLyBjb21waWxlIGVycm9yOiBrIGlzIG5vbi1jb25zdAoKICBYICp4cCA9IG5ldyBYW2tdOyAgICAgICAvLyBjb21waWxlIGVycm9yOiBubyBkZWZhdWx0IGNvbnN0cnVjdG9yCiAgWSAqeXAgPSBuZXcgWVtrXTsKCiAgc3RkOjp2ZWN0b3I8WD4geHYoMTApOyAgLy8gY29tcGlsZSBlcnJvcjogbm8gZGVmYXVsdCBjb25zdHJ1Y3RvcgogIHN0ZDo6dmVjdG9yPFk+IHl2KDEwKTsKCiAgZGVsZXRlIFtdIHlwOwogIHJldHVybiAwOwp9
prog.cpp: In function 'int main()':
prog.cpp:11:9: error: no matching function for call to 'X::X()'
X x1[n]; // compile error: no default constructor
^
prog.cpp:11:9: note: candidates are:
prog.cpp:3:12: note: X::X(int)
struct X { X(int i) { x = i; }; int x; };
^
prog.cpp:3:12: note: candidate expects 1 argument, 0 provided
prog.cpp:3:8: note: X::X(const X&)
struct X { X(int i) { x = i; }; int x; };
^
prog.cpp:3:8: note: candidate expects 1 argument, 0 provided
prog.cpp:16:18: error: no matching function for call to 'X::X()'
X *xp = new X[k]; // compile error: no default constructor
^
prog.cpp:16:18: note: candidates are:
prog.cpp:3:12: note: X::X(int)
struct X { X(int i) { x = i; }; int x; };
^
prog.cpp:3:12: note: candidate expects 1 argument, 0 provided
prog.cpp:3:8: note: X::X(const X&)
struct X { X(int i) { x = i; }; int x; };
^
prog.cpp:3:8: note: candidate expects 1 argument, 0 provided
prog.cpp: In constructor 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const value_type&, const allocator_type&) [with _Tp = X; _Alloc = std::allocator<X>; std::vector<_Tp, _Alloc>::size_type = unsigned int; std::vector<_Tp, _Alloc>::value_type = X; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<X>]':
prog.cpp:19:23: error: no matching function for call to 'X::X()'
std::vector<X> xv(10); // compile error: no default constructor
^
prog.cpp:19:23: note: candidates are:
prog.cpp:3:12: note: X::X(int)
struct X { X(int i) { x = i; }; int x; };
^
prog.cpp:3:12: note: candidate expects 1 argument, 0 provided
prog.cpp:3:8: note: X::X(const X&)
struct X { X(int i) { x = i; }; int x; };
^
prog.cpp:3:8: note: candidate expects 1 argument, 0 provided
prog.cpp:19:23: note: when instantiating default argument for call to std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const value_type&, const allocator_type&) [with _Tp = X; _Alloc = std::allocator<X>; std::vector<_Tp, _Alloc>::size_type = unsigned int; std::vector<_Tp, _Alloc>::value_type = X; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<X>]
std::vector<X> xv(10); // compile error: no default constructor
^