sorry for (probably) stupid question but I don’t know how to solve the problem.
I am using ROOT 6.18.04 on osx High Sierra; the problem is: when I compile my simple test code with: g++ prova3.cpp root-config --cflags -- libs -o prova3
I get the following error:
**prova3.cpp:23:5:** **error:** **static data member 'fgIsA' not allowed in local class**
**'Event'**
**ClassDef(Event,1)**
**^**
**/sw/share/root/include/Rtypes.h:327:4:** **note:** **expanded from macro 'ClassDef'**
**_ClassDefOutline_(name,id,virtual,) \**
**^**
**/sw/share/root/include/Rtypes.h:303:29:** **note:** **expanded from macro**
**'_ClassDefOutline_'**
**static atomic_TClass_ptr fgIsA; \**
**^**
**1 error generated.**
My code is:
#include "TROOT.h"
#include "TFile.h"
#include "TTree.h"
#include <fstream>
#include <iostream>
#include "TObject.h"
using namespace std;
int main() {
class example_1 {
public:
//Int_t pippo;
Int_t croc1[32], croc2, croc3, croc4;
};
class Event : public TObject {
public:
example_1 ex;
ClassDef(Event,1)
};
TFile fout("test_11.root", "recreate");
TTree *tree = new TTree("tree","tree");
Event *evento = new Event;
tree->Branch("event",&evento);
Int_t n_eventi = 10000;
for (Int_t i = 0; i < n_eventi; i++) {
if(i % 1000 == 0) cout << "Processing event " << i << "... " << endl;
evento->ex.croc1[0] = 22;
evento->ex.croc1[1] = -23;
tree->Fill();
}
tree->Write();
}
Ciao Francesco!
That compiler error says that your class Event can’t have a static data member fgIsA if it’s defined inside main (it’s the ClassDef macro that puts fgIsA into your class). It should be enough to take the class definitions out of the main function to fix it.
thank for your support; I did two files: prova3.h and prova3.cpp. In prova3.h there is:
#include "TObject.h"
class Det {
public:
Int_t croc1[32], croc2, croc3, croc4;
};
class Event : public TObject {
public:
Det ex;
ClassDef(Event,1)
};
While in prova.cpp there is:
#include "TROOT.h"
#include "TFile.h"
#include "TTree.h"
#include <fstream>
#include <iostream>
#include <TInterpreter.h>
#include "TObject.h"
#include "prova3.h"
using namespace std;
int main() {
TFile fout("test_11.root", "recreate");
TTree *tree = new TTree("tree","tree");
Event *evento = new Event;
tree->Branch("event",&evento);
Int_t n_eventi = 10000;
for (Int_t i = 0; i < n_eventi; i++) {
if(i % 1000 == 0) cout << "Processing event " << i << "... " << endl;
evento->ex.croc1[0] = 22;
evento->ex.croc1[1] = -23;
tree->Fill();
}
tree->Write();
}
Now compiling always with: g++ prova3.cpp $(root-config --cflags --libs) -o prova3
I get the following error:
Undefined symbols for architecture x86_64:
"Event::Class()", referenced from:
TClass* ROOT::Internal::GetClassHelper<Event>(bool, bool, std::__1::integral_constant<bool, true>) in prova3-45dd9c.o
"vtable for Event", referenced from:
Event::Event() in prova3-45dd9c.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Assuming you meant class Det and not Class Def…I’m not sure why data gets written in one case and doesn’t in the other. Maybe @pcanal can shed some light on this. You don’t get any runtime warning?