RE: new classes

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Fri, 30 Jun 2006 17:20:15 -0500


Hi,  

You need to generate a dictionary (search for rootcint in the User's guide) for your classes.  

Cheers,
Philippe


From: owner-roottalk_at_pcroot.cern.ch [mailto:owner-roottalk_at_pcroot.cern.ch] On Behalf Of Mario Kadastik
Sent: Friday, June 30, 2006 4:07 PM
To: roottalk_at_cern.ch
Subject: [ROOT] new classes

Hello,

could someone please help me as I'm utterly confused.

I'd like to create a new object to be used in TTree -s. I did create the following:

MyEvent.h



#include "TObject.h"
#include <cstdlib>

using namespace std;

class MyEvent : public TObject {
public:
MyEvent();
~MyEvent() {};
void setNr(Int_t nr);
Int_t getNr();
private:
Int_t nr;
ClassDef(MyEvent,1)
};

MyEvent.cpp



#include "TObject.h"
#include "MyEvent.h"
#include <cstdlib>

using namespace std;

void MyEvent::setNr(Int_t nr_new) {
nr = nr_new;
}

Int_t MyEvent::getNr() {
return nr;
}

MyEvent::MyEvent() {
nr=0;
}

ClassImp(MyEvent);

test.cpp



#include "TObject.h"
#include "MyEvent.h"
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char **argv) {
MyEvent * ev = new MyEvent();
ev->setNr(1);
cout << "Event nr: " << ev->getNr() << endl; return 0;
}

compiling it results in this:

[oberon] /home/mario/pythia/test > g++ -o libparticles.so -shared -rdynamic -O -Wall -fPIC MyEvent.cpp `root-config --cflags --libs --glibs` [oberon] /home/mario/pythia/test > g++ -o test test.cpp `root-config --cflags --libs --glibs` -L$PWD
-lparticles/home/mario/pythia/test/libparticles.so: undefined reference to `vtable for MyEvent'
/home/mario/pythia/test/libparticles.so: undefined reference to `ROOT::GenerateInitInstance(MyEvent const*)' collect2: ld returned 1 exit status

what am I doing wrong? I really need just a basic class with some objects to use in trees. The trouble is there is no simple example I could reference ...



Mario Kadastik
CMS experiment
mario.kadastik_at_cern.ch

"Physics is like sex, sure it may give some practical results, but that's not why we do it"
--- Richard P. Feynman Received on Sat Jul 01 2006 - 00:21:29 MEST

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:59 MET