This line
A* a = new A[5];
requires A to be constructive by default. So a simple option is to add a default constructor to A :
A(): x(), y() {} // zero-initializes x and y
Note that in C ++ you can usually use std::vector<A> in this case. This requires all memory management, so there is no need to explicitly call new and delete . It can also be changed dynamically. This would create std::vector<A> with five default A objects built:
std::vector<A> a(5);
although you probably want to create an empty one and insert values ββinto it in the loop.
std::vector<A> a; for(i=0;i<5;i++) { a.push_back(A(i, 10)); }
source share