Special case of dynamically allocating a class of objects.

I have a class template here that has a default constructor and another constructor that can take in one parameter to initialize the object.

I want to dynamically allocate objects for this class such that they are all initialized with a value from a variable that I will get from the user as the parameter of the non-default constructor.

I know a regular dynamic allocation for class templates is something like:

class < int > *ObjectPtr;
ObjectPtr = new class < int > [size];

...but does C++ allow me to new[] without calling the default constructor? I don't know the proper syntax. =S



Thanks in advance.
It is not possible. You cannot pass arguments to an array initializer. http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.5

std::vector<int> foo(30, 4); // a vector of 30 4s.

Vector requires a copy constructors to initialize each element with a default value.
Ah, thank you so much! This is exactly what I need to solve this problem! =D
Topic archived. No new replies allowed.