This complete session works interactively, just two commands create 4 canvases:
root [0] TCanvas c[10];
root [1] for (Int_t j=1;j<5;j++){TCanvas c[j] = new TCanvas(Form(“name_%02d”,j),Form(“Canvas#%02d”,j),100j,100j,800,600);c[j]->Divide(2,2);}
root [2] .q
root -x trick.cxx fails with the following file:
void trick(){
cout << “v11 Simulation Analysis” << endl ;
//TCanvas *c[10];
static const unsigned ten = 10;
TCanvas c[ten];
for (Int_t j=1;j<5;j++) { TCanvas c[j] = new TCanvas(Form(“name_%02d”,j),Form(“Canvas#%02d”,j),100j,100j,800,600);
c[j]->Divide(2,2);}
}
Error message:
Error: Non-static-const variable in array dimension trick.cxx:6:
(cint allows this only in interactive command and special form macro which
is special extension. It is not allowed in source code. Please ignore
subsequent errors.)
*** Interpreter error recovered ***
This complete session works interactively, just two commands create 4 canvases:
root [0] TCanvas c[10];
root [1] for (Int_t j=1;j<5;j++){TCanvas *c[j] = new TCanvas(Form(“name_%02d”,j),Form(“Canvas#%02d”,j),100j,100*j,800,600);c[j]->Divide(2,2);}
root [2] .q
[/quote]
First, you declare TCanvas * c[10], ok.
Now you want to initialize it in a loop -
you do not need ‘TCanvas *’, what you have - is an invalid expression, use just c[j] = …