Calling variables dynamically

Hi all,

I have big bunch of objects with names like

TBarrelHisto_1_1, TBarrelHisto_1_2, TBarrelHisto_1_3, ... , TBarrelHisto_33_71,

so about ~2500 of them. I would like to perform the same operation with all of them, but I don't want to write 2500 lines of code. Is there any way to refer to them in a loop? Something like

for(int i;i<34;i++){
for(int j;j<72;j++){
TBarrelHisto_i_j.Operation();
}
}

Thanks!
are you telling us, that you have defined separate ~2500 objects? Just declare an array of objects, like this:
1
2
3
4
5
6
7
8
//class A with Operation() method
A objectArray[x][y]; // x,y constanst or make it dynamically
//...
for(int i = 0; i < x ; i++)
    for(int j = 0; j < y; j++)
        objectArray[i][j].Operation();


Last edited on
Yeah, the problem is that I read all these objects from a ROOT file (ROOT is a program used in particle physics), so I don't create the objects, they are given to me in the format I wrote.
Topic archived. No new replies allowed.