Root error: call to deleted constructor of 'TFile'

can anybody help me to solve the problam as shown in figure? many thanks

[molh@login1 build-test]$ root plotHisto.C

| Welcome to ROOT 6.24/02 https://root.cern |
| (c) 1995-2021, The ROOT Team; conception: R. Brun, F. Rademakers |
| Built for linuxx8664gcc on Jun 28 2021, 09:28:51 |
| From tags/v6-24-02@v6-24-02 |
| With c++ (GCC) 9.3.0 |

Try ‘.help’, ‘.demo’, ‘.license’, ‘.credits’, ‘.quit’/’.q’

root [0]
Processing plotHisto.C…
/csns_workspace/ANIS/molh/practice/particleGun/build-test/./plotHisto.C:7:9: error: call to deleted constructor of ‘TFile’
TFile f = TFile(“run2.root”);
^ ~~~~~~~~~~~~~~~~~~
/cvmfs/software.csns.ihep.ac.cn/softwares/root-6.24.02-gcc9.3-cxx11/include/TFile.h:172:4: note: ‘TFile’ has been explicitly marked deleted here
TFile(const TFile &) = delete; //Files cannot be copied

Your code is invoking an assignment operator, which often calls the copy constructor (or vice versa). What you should be doing is simply instantiating an object with an argument:

TFile f("run2.root");

image

Many thanks. There is another error.

This is really not the appropriate place for ROOT support :slight_smile: ROOT has their own web site (https://root.cern.ch) and discussion forums (https://root-forum.cern.ch).

For this specific issue, most of the ROOT “Get()” functions return a pointer to the TObject base class, and you need to cast the object to the type you actually want. You do exactly that on the very next line of your code.