   How Do I Create Multiple Objects Without Declaring Them, With A Loop?
  Hello All!,I am creating a loop that creates 6 clocks with random time zones. What I am unclear on is this: How do I create multiple objects without actually declaring them? I am trying to have a loop do it all for me.Do I do it by this?: Clock clock[y]  ????How do I add a letter or number to the end of the name of the object so it differs from the other?Thanks!   for ( int y = 0; y < 7; y++){   Clock clock[y] = new Clock(timeZoneIds[random], xplace, yplace);   xplace += 100;   yplace += 100;   clock.draw(page);    }[edited by - Klear on March 24, 2004 5:02:34 PM]
Clock* clocks[7];for ( int y = 0; y < 7; y++){   clocks[y] = new Clock(timeZoneIds[random], xplace, yplace);xplace += 100;yplace += 100;clock.draw(page);    };  Thanks for the reply, but I am getting errors... ClockDriver.java [52:1] not a statement Clock* clocks[7]; ^1 errorErrors compiling ClockDriver. [edited by - Klear on March 24, 2004 5:17:37 PM];  That might be because the replier posted C++ code?!   DISCLAIMER: If any of the above statements are incorrect, feel free to deliver me a good hard slap!My games: DracMan | Swift blocks;  Clock ** clocksclocks = new (Clock *)[7];for(i=0;i<7;++i)clocks = new Clock();for(i=0;i<7;++i)delete clocks;<br><br>delete[] clocks;<br><br><br>  </i>  ;  Hmm yea your prolly right. = / This is Java source btw ;  That s because you are using java and peter_b thought you used c++. Clock clock[7];for ( int y = 0; y < 7; y++){   clock[y] = new Clock(timeZoneIds[random], xplace, yplace);   xplace += 100;   yplace += 100;   clock[y].draw(page);    }LizardCPP   [edited by - LizardCPP on March 24, 2004 5:24:03 PM];quote:Original post by LizardCPP  That s because you are using java and peter_b thought you used c++. Clock clock[7];for ( int y = 0; y < 7; y++){   clock[y] = new Clock(timeZoneIds[random], xplace, yplace);   xplace += 100;   yplace += 100;   clock[y].draw(page);    }LizardCPP   Thanks man but... ClockDriver.java [52:1] '']'' expected Clock clock[7];   ^1 errorErrors compiling ClockDriver.;quote:Original post by Klear   quote:Original post by LizardCPP    That s because you are using java and peter_b thought you used c++. Clock clock[7];for ( int y = 0; y < 7; y++){   clock[y] = new Clock(timeZoneIds[random], xplace, yplace);   xplace += 100;   yplace += 100;   clock[y].draw(page);    }LizardCPP   Thanks man but... ClockDriver.java [52:1] ']' expected Clock clock[7];   ^1 errorErrors compiling ClockDriver. ah thats right....you have to do Clock clock[] = new Clock[7]; first then the for-statement.   [edited by - LizardCPP on March 24, 2004 5:28:13 PM];quote:Original post by LizardCPP    quote:Original post by Klearquote:Original post by LizardCPP That s because you are using java and peter_b thought you used c++. Clock clock[7];for ( int y = 0; y < 7; y++){   clock[y] = new Clock(timeZoneIds[random], xplace, yplace);   xplace += 100;   yplace += 100;   clock[y].draw(page);    }LizardCPP   Thanks man but... ClockDriver.java [52:1] ']' expected Clock clock[7];   ^1 errorErrors compiling ClockDriver. ah thats right....you have to do Clock clock = new Clock[7]; first then the for-statement.   Thanks for hanging in Lizard  Now its saying that I need an array? Are the brackets not doing that?    ClockDriver.java [52:1] incompatible typesfound   : Clock[]required: Clock Clock clock = new Clock[7];^ClockDriver.java [55:1] array required, but Clock found   clock[y] = new Clock(timeZoneIds[random], xplace, yplace);   ^ClockDriver.java [58:1] array required, but Clock found   clock[y].draw(page);   ^3 errorsErrors compiling ClockDriver. [edited by - Klear on March 24, 2004 5:28:41 PM] [edited by - Klear on March 24, 2004 5:29:22 PM]