D
Denis Remezov
Kutty said:Hi,
MyClass *myclass_=new MyClass[100];
and MyClass::MyClass(int) and no default constructor. My object assignment
obviously gives an error. So waht is the correct way to do it without using
vectors of course.
kutty
Technically, it is possible to use placement new to construct objects of MyClass
on a previously allocated pool. You would then call new(address) MyClass(value)
iteratively and you could even pass a different value to the constructor each
time. There are a couple of issues with that approach that might not be
immediately obvious. The syntax for destruction is different from normal
as well. See FAQ 11.10 and 11.14 (www.parashift.com/c++-faq-lite).
Practically, placement new should better be avoided if there is a sensible
alternative. Why not use a vector?
Denis