Object visibility problem?

Hi! Although the “feature” I encountered was in the ConfigPPR.C file of aliroot I post the message here because I guess it is a general C++ matter. Here it goes: We have the following piece of code:

if (iTOF) {
AliTOF *TOF = new AliTOFv4T0(“TOF”, “normal TOF”);

iTOF is set to TRUE (1). Later in the code I try to put the line:


The system complaints that TOF is undeclared. Is this the expected behaviour? Once the TOF object is declared and instantiated should’t it be known in the function scope? If I put the above line inside the if braces there is no problem.

This is illegal. You must declared your object AliTOF outside the if
scope if you want to use it later
Simply do

AliTOF *TOF=0;
if (iTOF) {
TOF = new AliTOF(…

now you can use TOF