We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › On creating lots of objects...
Page Index Toggle Pages: 1
On creating lots of objects... (Read 436 times)
On creating lots of objects...
Dec 31st, 2006, 11:56pm
 
I'm rather new to programming in general, so this may seem silly.  If I want to create many new objects of some class, and wanted them to all have different names, how could I do that?
Re: On creating lots of objects...
Reply #1 - Jan 1st, 2007, 12:08am
 
And by many I mean upwards of 1000, and I need it to be triggered by something, if that makes it any different.
Re: On creating lots of objects...
Reply #2 - Jan 1st, 2007, 12:19am
 
by "having different names" you mean variables holding them?

i think you should rather look into arrays or Vector .. like:

Code:

class MyObj {
MyObj ( int _i )
{
println( "created #" + _i);
}
}
MyObj myobjs[] = new MyObj[1000];
for (int i=0; i<myobjs.length; i++)
{
myobjs[i] = new MyObj(i);
}


F
Re: On creating lots of objects...
Reply #3 - Jan 1st, 2007, 12:22am
 
oh, yeah, that could work.
thanks a lot.
Page Index Toggle Pages: 1