|
Author |
Topic: n insance with parameter (4 dummies) (Read 221 times) |
|
gabon
|
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
|
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
|
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.
|
|
|
|
|