Go Down

Topic: multi dimensional arrays and creating classes (Read 1 time) previous topic - next topic

follower

Quote
Your class requires a constructor with parameters, which you can't provide in an array definition.

Actually, this code is an example that creates an array of four EchoServer objects the constructor of which takes a single parameter:
Code: [Select]
EchoServer servers[4] = {7, 8, 9, 10};

Quote
You need to make an array of pointers, not an array of your class.

The question of whether the OP actually wants/needs all the objects created at once is a valid one which would influence the best solution.

--Phil.

roypardi

Quote
Or just make your constructor do nothing and provide an init() method.  I think then you'd be able to make an array of objects (though I haven't actually tried it).

- Ben


It works - this is the way I figured out how to do it when faced with the same issue and not knowing any other way to do it.

--Roy

bens

Quote
Actually, this code is an example that creates an array of four EchoServer objects the constructor of which takes a single parameter:
Code: [Select]
EchoServer servers[4] = {7, 8, 9, 10};

That's good to know!

- Ben

tehboii

And just found out this would work with multiple parameters constructors :
Code: [Select]

     incident incidents[4] = {
           incident(1,1),
           incident(2,2),
           incident(3,3),
           incident(4,4)};


There does not seem to be a simplified notation for this.
... could use some sleep

kBit

#9
Jun 10, 2008, 04:10 am Last Edit: Jun 10, 2008, 04:10 am by kBit Reason: 1
Repeat with me, C arrays go from 0 to n-1.

{Not counting fixing any other errors.}

Code: [Select]
for (indexCounter=0; indexCounter <= length of array;  indexCounter++) // length of array?
       Serial.print(incident[indexCounter].time); (//??)


should be

Code: [Select]
for (indexCounter=0; indexCounter < length of array;  indexCounter++) // length of array?
       Serial.print(incident[indexCounter].time); (//??)



Go Up