How Do I Create Multiple Objects Without Declaring Them, With A Loop?

Started by
14 comments, last by Klear 20 years, 1 month ago
you didn''t copy his code right:

Clock clock[] = new Clock[7];

NOT

Clock clock = new Clock[7];

-me
Advertisement
hah thanks. I just jump the gun all the time when I am into something Thanks For all the help.
quote:Original post by Anonymous Poster
Clock ** clocks

clocks = new (Clock *)[7];

for(i=0;i<7;++i)
clocks = new Clock();


This is so ugly, why a double pointer, newing an array with a cast etc ?
A class is stored as a pointer anyway, so why this indirection ? Why not just

Clock clocks[7];
for(i=0;i<7;i++) {
clocks = new Clock();<br>} </i>
quote:Original post by Fidelio66

This is so ugly, why a double pointer, newing an array with a cast etc ?
A class is stored as a pointer anyway, so why this indirection ? Why not just

Clock clocks[7];
for(i=0;i<7;i++) {
clocks = new Clock();
}


Ugly? UGLY?! Well, how about THIS!

void DoStuffL(){  RPointerArray< Clock > iClocks;  for ( TInt i = 0; i < 7; ++i )  {    Clock *iClock = Clock::NewL();    CleanupStack:: Push( iClock );    iClocks.Append( iClock );  }  for ( TInt i = 0; i < 7; ++i ) CleanupStack:: Pop();}  

(I'm sure someone who actually knows symbian can point out quite a few mistakes with that code. And I thought microsoft's code looked bad..)

[edited by - Painless on March 24, 2004 7:06:37 PM]
Why can't you just do
Clock clocks[7]?

Oh, you have a non-trivial ctor, that's why. Evil, pure evil.

[edited by - Magmai Kai Holmlor on March 24, 2004 8:59:15 PM]
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
quote:
Ugly? UGLY?! Well, how about THIS!
void DoStuffL() 

{snip}

You want the stability, you gotta pay the price....

[edited by - shmoove on March 25, 2004 4:22:59 AM]

This topic is closed to new replies.

Advertisement