I wrote the following code:
#include <iostream>
struct A
{
int a;
A(int){ std::cout << "A(int)" << std::endl; }
A(){ std::cout << "A()" << std::endl; }
~A(){ std::cout << "~A()" << std::endl; }
};
int main()
{
A *a = new A[100];
delete[] a;
}
But I wanted to call A(2)
while constructing the array, not A()
. I tried this:
new (2) A[100];
, but the argument 2
is passed to the operator new[]
. new A(2)[100];
doesn't work either.