Author Topic: Adding a class instance to an array  (Read 4688 times)

byates

  • Senior Community Member
  • Posts: 106
  • Hero Points: 8
Adding a class instance to an array
« on: February 14, 2009, 11:46:13 PM »
I am playing with Slick-C classes and have the following question:

What is the most efficient way to add a class instance to an array?
Code: [Select]
tcClassType MyArray[];
for(i=0;i<SomeCount;i++)
    {
    MyArray[i] = new class instance()  <- what is the correct syntax???
    }
This syntax gives an error:
Code: [Select]
for(i=0;i<SomeCount;i++)
    {
    MyArray[i] = tcClassType(parm1, parm2,...);
    }

I can do this, but is requires an extra deep copy of the instance:
Code: [Select]
for(i=0;i<SomeCount;i++)
    {
    tcClassType MyClassInst(parm1,parm2,...);
    MyArray[i] = MyClassInst;
    }
Is there a better syntax?

Thanks!
« Last Edit: February 15, 2009, 04:33:39 PM by byates »