# Error: variable-sized object may not be initialized TChain

**URL:** <https://root-forum.cern.ch/t/error-variable-sized-object-may-not-be-initialized-tchain/36605>\
**Category:** Newbie\
**Tags:** tree, root\
**Created:** [October 31, 2019, 2:32pm UTC](https://root-forum.cern.ch/t/error-variable-sized-object-may-not-be-initialized-tchain/36605 "2019-10-31T14:32:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![burmau\_Garba](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/burmau_garba/32/20002_2.png) [@burmau\_Garba](https://root-forum.cern.ch/u/burmau_Garba)\
**Post date:** [October 31, 2019, 2:32pm UTC](https://root-forum.cern.ch/t/error-variable-sized-object-may-not-be-initialized-tchain/36605/1 "2019-10-31T14:32:50Z")

</div>

```auto
Error: variable-sized object may not be initialized TChain *gpChain[i] = new TChain(gpTreeNames[i]); 

```

WHAT CAN I DO TO TAKE THIS ERROR OFF MY CODE ? THANKS

```auto
 //Make gpChains
    TString gpChainNames[] = {"p100GeV", "p250GeV", "p500GeV", "p750GeV", "p1TeV", "p2TeV", "p5TeV", "p7hTeV", "p10TeV", "p12hTeV", "p15TeV", "p30TeV", "p45TeV", "p60TeV", "p70TeV", "p80TeV", "p90TeV"};
    
    TString gpTreeNames[] = {"t","t","t", "mcevent", "t", "t", "mcevent", "mcevent", "mcevent", "mcevent", "mcevent", "mcevent", "mcevent", "mcevent", "mcevent", "mcevent", "mcevent"};
    const int gpSize = sizeof(gpChainNames)/sizeof(*gpChainNames);
    
    TChain **gpChain = new TChain*[gpSize];
    TString gpFileNames[gpSize], gpHistNames[gpSize], gpFitNames[gpSize], gpTitleNames[gpSize];
    for (int i = 0; i < gpSize; i++) {
      gpFileNames[i] = gpChainNames[i];
      gpFileNames[i].Insert(1,"_");
      gpFileNames[i].ReplaceAll("h",".5");
      
      gpHistNames[i] = gpChainNames[i];
      gpHistNames[i].Prepend("h");
      
      gpFitNames[i] = gpChainNames[i];
      gpFitNames[i].Prepend("f");

      gpTitleNames[i] = gpChainNames[i];
      gpTitleNames[i].Remove(0,1);
      gpTitleNames[i].ReplaceAll("h",".5");
      gpTitleNames[i].Append(" Protons (" + TrigTxt + " MeV Threshold)");
      
     TChain *gpChain[i] = new TChain(gpTreeNames[i]);
      TString path = TString::Format("%s%s%s","/home/nutters/Tyler/RunsJan2018/SingleEnergy/New/",gpFileNames[i].Data(),".root");
      gpChain[i]->Add(path);
      gpChain[i]->SetLineColor(kBlack);
      gpChain[i]->SetLineWidth(2);
      
      //create friends for sparsified output
      gpChain[i]->Process("/home/nutters/Tyler/EnergyMeasurement/testDraw/G4CALFriendMaker.C+",gpChainNames[i]);
      
      //add them as a friend now
      gpChain[i].AddFriend("g4ff",gpChainNames[i]+"_G4CALFriend.root");
    }

```

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [October 31, 2019, 5:28pm UTC](https://root-forum.cern.ch/t/error-variable-sized-object-may-not-be-initialized-tchain/36605/2 "2019-10-31T17:28:27Z")

</div>

You must not redefine variables ("`TChain gpChain`" versus “`TChain **gpChain`”) then, “[`TChain(gpSize)`](https://root.cern.ch/doc/master/classTChain.html)” makes no sense and you should have “`gpChain[i] = new TChain(gpTreeNames[i]);`” (i.e. no “`TChain *`” in front of it).

---

<div class="post-metadata">

**Author:** ![burmau\_Garba](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/burmau_garba/32/20002_2.png) [@burmau\_Garba](https://root-forum.cern.ch/u/burmau_Garba)\
**Post date:** [November 1, 2019, 1:26pm UTC](https://root-forum.cern.ch/t/error-variable-sized-object-may-not-be-initialized-tchain/36605/3 "2019-11-01T13:26:35Z")

</div>

Thanks, I know about that error but that wasn’t the error I was talking about. The error is in the for-loop.

TChain \*gpChain[i] = new TChain(gpTreeNames[i]);
