Jul 6, 2010 at 3:38am UTC
For a static array, you can do this:
Test array[200]={3,1,4,1,5...};
Jul 6, 2010 at 4:09am UTC
No, there's no way to pass constructor parameters to objects constructed as part of dynamically allocated arrays.
Aug 10, 2010 at 7:46pm UTC
if you change your Test constructor to this.
Test(int nNum_i=0)
{
m_nNum = nNum_i;
}
it is default constructor with default argument,it will solve 2 purposes,it can use to construct object using dynamically allocated memory or simple object with arguments or withour arguments also.
hope this will solve ur problem.
Aug 11, 2010 at 11:07am UTC
You could reserve the memory and later construct the elements (one by one).
1 2 3 4 5 6 7
//allocator<Test> aux;
//Test *const array = aux.allocate(n);//reserve a block of memory
Test *const array =(Test *) malloc( sizeof (Test)*n );
//construct 1 object
//new ((void*)(array+i)) Test(value);
new (array+i) Test(value);
Or use Test **, or an STL container
Last edited on Aug 11, 2010 at 11:15am UTC