FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   n insance with parameter (4 dummies)
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: n insance with parameter (4 dummies)  (Read 221 times)
gabon

WWW
n insance with parameter (4 dummies)
« on: Sep 1st, 2004, 3:31pm »

if I would like to create n instances of a new class, how to do it. I tried:
 
Code:

column = new Striscia[10];
int laX=0;
for(int i=0; i<10; i=i+1)
{
  column[i]= new Striscia(laX);
  laX+=40;
}

 
but it talks about overloading, where is the mistake?
 
cheers, chr
 
gabon

WWW
Re: n insance with parameter (4 dummies)
« Reply #1 on: Sep 1st, 2004, 3:35pm »

the overloading obviously was for a mistake in the method
 
do u think it is correct anyway this code?
 
 
chr
 
TomC

WWW
Re: n insance with parameter (4 dummies)
« Reply #2 on: Sep 1st, 2004, 5:29pm »

Yes, that's the right way to make an array of class instances.
 
Just so you know, the special method with the same name as the class (the one which instantiates the class) is called a constructor.  You've found it now, but you probably hadn't overloaded the constructor with a version which took an int as a parameter.
 
Pages: 1 

« Previous topic | Next topic »