我尝试通过youtube视频教授CERN ROOT [视频标题是初学者的CERN ROOT教程 - 3.用结构和类编写一个树(例4-5)],但它没有用。
错误:未知类型名称' particle_CLASS'
这是我的代码
void example5() {
TTree t("t","a simple Tree with struct")
gSystem->Load ("particle_CLASS_h.so");
particle_CLASS* sParticle = new particle_CLASS();
t.Branch ("particle_info", &sParticle);
sParticle->Set_energy(11);
sParticle->Set_position(1.1, 2.2, 3.3);
t.Fill();
sParticle->Set_energy(99);
sParticle->Set_position(191., 291., 391.);
t.Fill();
TFile f("example5.root","recreate");
t.Write();
f.Close();
}
和partivle_CLASS.h代码
class particle_CLASS: public TObject {
private:
Float_t position[3];
Float_t energy;
public:
particle_CLASS() { } // empty constructor
//----Setter----
void Set_position(Float_t x, Float_t y, Float_t z)
{
position[0] = x; position[1] = y; position[2] = z;
}
void Set_energy(Float_t e) { energy = e;}
//----Getter----
Float_t* Get_position() { return position; }
Float_t Get_energy() { return energy; }
ClassDef(particle_CLASS,1)
/*
| ClassDef is a C preprocessor macro
| that must be used if your class derives from TObject.
*/
};