Array of THStack objects

I want to make make an array of 10 Stacks, to be “filled” in a for loop:

...

TH1F *histo[10];
THStack compa[10];

...

 c7->cd(j+1);
histo[j]->SetLineColor(kRed);
compa[j]->Add(sel);
compa[j]->Add(histo[j]);
compa[j]->Draw("nostack");

where histo[j] is filled during the same iteration, and sel is a previously defined histogram. The loop starts at j=0 and continues for j<10.

The Stack does not plot and I get the following warning message:

[quote]Warning: wrong member access operator ‘->’ HelicityAngle.C:245:
Warning: wrong member access operator ‘->’ HelicityAngle.C:246:
Warning: wrong member access operator ‘->’ HelicityAngle.C:247:
[/quote]
where the three lines in question refer to the last three lines of the code above.

What’s the problem? Is compa[j] an array of stacks?

Try to change “compa[j]->” into “compa[j].”.

thanks,
The message is gone, but it still does not print to the canvas

Well, if it’s inside of a function (e.g. a “named macro”) then all “THStack compa[10];” will automatically be deleted at “return”.
If you want them to live longer, you will need to switch to “THStack *compa[10];”

thanks,
so now I’m declaring the Stack outside the for loop as THStack *compa[10];,

but then I get an error [quote]Error: illegal pointer to class object compa[j] 0x0 2111 HelicityAngle.C:245:
[/quote] at the line corresponding to compa[j].Add(sel);.

If this doesn’t work, can I declare a single THStack inside the for loop and “clear” it after each iteration?

compa[j] = new THStack(); // create the stack
compa[j]->Add(sel); // add the first histogram