Error/Problem with object from a class made by MakeClass

Hey.

I’ve got a root file with a Tree T in it and now I’ve made

T->MakeClass(“myclass”)

and I’ve got a myclass.h and a myclass.C. So that worked. But when I try to get an object of this class

myclass object(tree)

in my main.cxx it says

error: must use ‘class’ tag to refer to type ‘myclass’ in this scope

I don’t understand that error. I’ve included myclass.h and myclass.C.


Try with a “main.cxx” in form:

#include "TTree.h"
#include "myclass.C"
int main(void) {
  TTree *tree = 0;
  myclass object(tree);
  return 0;
}

Thanks for your answer.

My file starts witth

TFile *fs = new TFile(“file_read.root”, “READ”); //The root file where tree is in
TFile *fs1 = new TFile(“file_write.root”, “RECREATE”);
TTree *sig = (TTree *)fs->Get(“tree”);
myclass tree_sig(sig);

So I can’t set the pointer on 0 ? Or should I change it to:

TFile *fs = new TFile(“file_read.root”, “READ”); //The root file where tree is in
TFile *fs1 = new TFile(“file_write.root”, “RECREATE”);
TTree *sig=0;
TTree *sig = (TTree *)fs->Get(“tree”);
myclass tree_sig(sig);

Try:

#include "TFile.h"
#include "TTree.h"
#include "myclass.C"
int main(void) {
  TFile *fs = TFile::Open("file_read.root");
  if ((!fs) || fs->IsZombie()) { delete fs; return 1; } // just a precaution
  TTree *sig; fs->GetObject("tree", sig);
  if (!sig) { delete fs; return 2; } // just a precaution
  TFile *fs1 = TFile::Open("file_write.root", "RECREATE");
  if ((!fs1) || fs1->IsZombie()) { delete fs1; delete fs; return 3; } // just a precaution
  // ...
  myclass tree_sig(sig);
  // ...
  delete fs1;
  // delete fs; // will be deleted by the "myclass" destructor (deletes "sig", too)
  return 0;
}

Ok, I’ve figured it out. It was a really stupid mistake I made: I’ve forgot to load my .C File in root before running the script.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.