ROOT6 Error: Use of Undeclared Identifier

Hi,

I am getting an error “Use of Undeclared Identifier” in ROOT 6 while running a script which I didn’t have a problem with in ROOT 5. My script has something like:

if (condition 1) {
Jet *jet1 = (Jet*) branchJet->At(0);
}
if (condition 2) {
Here I use jet1 to calculate some other variable.
}

Now condition 2 is never met if condition 1 is false. However, ROOT 6 returns this:
error: use of undeclared identifier ‘jet1’

I don’t know how it is executing the second if statement and trying to use ‘jet1’ given that this statement must be false. I have seen another post complaining about a similar issue but with histograms. Hope you can help.

Many thanks,
Amin

You cannot use jet1 within the 2nd condition. It is declared within the curly bracket of the 1st condition and known there only. So you should do:

Jet *jet1 = 0;
if (condition 1) {
   jet1 = (Jet*) branchJet->At(0);
}
if (condition 2) {
   Here I use jet1 to calculate some other variable.
}
1 Like

Thank you Olivier. It works.

Best,
Amin