new classes

From: Mario Kadastik <>
Date: Sat, 1 Jul 2006 00:06:44 +0300


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:


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

using namespace std;

class MyEvent : public TObject {

   ~MyEvent() {};
   void setNr(Int_t nr);
   Int_t getNr();

   Int_t nr;


#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() {




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

using namespace std;

int main(int argc, char **argv) {

         MyEvent * ev = new MyEvent();
         cout << "Event nr: " << ev->getNr() << endl;
         return 0;


compiling it results in this:

[oberon] /home/mario/pythia/test > g++ -o -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/ undefined reference to `vtable for MyEvent' /home/mario/pythia/test/ 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

"Physics is like sex, sure it may give some practical results, but that's not why we do it"

Received on Fri Jun 30 2006 - 23:06:54 MEST

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