#include <iostream> #include <new> class A { public: int x; public: A(int x = 0) : x(x) { std::cout << "In " << __func__ << ", x = " << x << std::endl; } }; int main(int argc, char* argv[]) { const int N = 10; A* array = new A[N]; for (int i = 0; i < N; ++ i) { new (array + i) A(i); } for (int i = 0; i < N; ++ i) { std::cout << array[i].x << std::endl; } return 0; }
Standard input is empty
In A, x = 0 In A, x = 0 In A, x = 0 In A, x = 0 In A, x = 0 In A, x = 0 In A, x = 0 In A, x = 0 In A, x = 0 In A, x = 0 In A, x = 0 In A, x = 1 In A, x = 2 In A, x = 3 In A, x = 4 In A, x = 5 In A, x = 6 In A, x = 7 In A, x = 8 In A, x = 9 0 1 2 3 4 5 6 7 8 9