Hello.
I am trying to make my own class and store objects of it on a tree.
My class looks like this:
Point.cpp:
#include <TObject.h>
class Point : public TObject
{
private:
float x;
float y;
float z;
public:
Point(float x, float y, float z);
void SetPoint(float x, float y, float z);
float GetPointX(void);
float GetPointY(void);
float GetPointZ(void);
ClassDef(Point, 1);
};
Point::Point(float x, float y, float z)
{ this->x = x; this->y = y; this->z = z; }
void Point::SetPoint(float x, float y, float z)
{ this->x = x; this->y = y; this->z = z; }
float Point::GetPointX(void)
{ return this->x; }
float Point::GetPointY(void)
{ return this->y; }
float Point::GetPointZ(void)
{ return this->z; }
#if !defined(_CINT_)
ClassImp(Point);
#endif
.
My program is the following.
treestuff.cpp:
#include <stdio.h>
#include <TFile.h>
#include <TTree.h>
#include <TObject.h>
#include "Point.cpp"
int go(void)
{
if (!TClass::GetDict("Point"))
gROOT->ProcessLine(".L Point.cpp+");
TFile *file = new TFile("foo.root","RECREATE","practice file");
TTree *tree = new TTree("tree1","A glorious tree");
Point *pnt = new Point(0,0,0);
tree->Branch("PointBranch","Point",&pnt);
return 0;
}
When I literally type what is in my program directly into the interpreter, everything seems to work fine, but when I try to do it by loading treestuff.cpp, I get the following output.
root [0] .L treestuff.cpp
root [1] go()
Error in <TTree::Branch>: The actual class (TObject) of the object provided for the definition of the branch "PointBranch" does not inherit from Point
(int)0
I don’t know what to make of this error. My object *pnt seems to be of class Point, not just TObject…