Filling arrays the easy way

I've got a large collection of objects:

T01, T02, ... , T41.

These objects belong to a class Class with a member function F:
double F(const Class* C)

What I want to do is use a loop to go through the entire list of objects, and extract a double value from each of them using F, storing these double values in an array.

Currently I'm doing this mechanically:

1
2
3
4
5
6
double values[41];
values[0] = T01->F(T99);
values[1] = T02->F(T99);
values[2] = T03->F(T99);
...
values[40] = T41->F(T99);

I don't want to need to type all that out. Soon I'll need to work with thousands of these objects and the above method will be impractical.

Something like the this would be better:
1
2
3
4
double values[41];
for(int i = 0; i <= 41; i++) {
  values[i] = T<i in two digits>->F(T99);
}


Note that by <i in two digits> in mean that I'd like to call T<file number>. Someone here suggested that I enter all the objects into an array, but that just moves the problem to getting all the objects into the array! Thanks -*
What you have described isn't possible in c++ (it may be possible to simulate this effect using preprocessor macros but that would be extremely difficult). The name of an object is not something that can be generated dynamically. You will have to make an array of Class objects and then access each one through that array. Getting all the objects into the array would make things easier on whoever has to create them. In the example above, each one of the T objects would have to have been created 'mechanically'. So if you really wanted to have thousands of them an array is the only way to go.
Thanks. I'm sure there must be an easier way. This might sound ridiculous, but I've thought of writing code that generates code like that on lines 2-6 (on first code-block in original post) and writes it to a text file. Then I could paste that into my program. Just seems like a very silly way of doing it.
1
2
double values[41];
for(int i = 0; i <= 41; i++) {



Incorrect! Loop only until i < 41.

Let me ask you; why are the TXX objects not within an array in the first place? If you are going to have thousands of them are you going to have a thousand different variables for the objects? Why not make an array of those as well?
Noted. But you got the idea. Actually, I'm working in a framework called ROOT, which uses C++. I've seen that there are iterators in the ROOT framework which will allow easier access to these objects. I think the objects are stored in a linked list. I have learned a little about what C++ cant do though.
Topic archived. No new replies allowed.