Class Definitions in Makros

From: Volker Hejny (V.Hejny@fz-juelich.de)
Date: Fri Aug 13 1999 - 12:53:02 MEST


Hallo,

sorry, it's me again, but I don't understand the following 
behaviour:

I have written these files:

----  EMModule.hh
#ifndef _EMModule_H_
#define _EMModule_H_

#ifdef GNUPRAGMA
#pragma interface
#endif

#ifdef ROOTCINT
# include "TVector3.h"
#endif

class EMModule: public TVector3 {
 private:
  Float_t	size;
 public:
  EMModule();
  EMModule(Float_t x, Float_t y, Float_t z, Float_t s);
  EMModule(TVector3 x, Float_t s);
  ~EMModule();
  Float_t Size();

#ifdef ROOTCINT
  ClassDef(EMModule,1)
#endif
       
};

#endif

---- EMModule.cc
#ifdef GNUPRAGMA
#pragma implementation
#endif

#include "EMModule.hh"

#ifdef ROOTCINT
 ClassImp(EMModule)
#endif

// member functions for EMModule

EMModule::EMModule() : TVector3() {
  cout << "Warning: default constructor for EMModule called." << endl;
  size = 0.;
}

EMModule::EMModule(Float_t x, Float_t y, Float_t z, Float_t s) :
  TVector3(x,y,z) {
  size = s;
}

EMModule::EMModule(TVector3 x, Float_t s) : TVector3(x) {
  size = s;
}

EMModule::~EMModule() : {}

EMModule::Size() { 
  return size;
}

----

Then I did:

root [0] .L EMModule.cc
root [1] EMModule x3(1,2,3,4)
root [2] cout << x3(1) << endl;
2

After that I tried to reload the file (as I understood this should work):

root [3] .L EMModule.cc
root [4]

Ok, this was alright. Then I did (with a restarted root):

root [0] .L EMModule.cc
root [1] TVector3 y(1,2,3)
root [2] EMModule x3(y,4);
root [3] cout << x3(1) << endl;
2
root [4] .L EMModule.cc

 *** Break *** segmentation violation
Root > 
 
Strange, but here is the next try:

root [0] .L EMModule.cc
root [1] TVector3 *y = new TVector3(1,2,3)
root [2] EMModule x3(y,4);
root [3] cout << x3(1) << endl;
2
root [4] .L EMModule.cc
root [5] 

This again works ...

The effect is reproduceable. In general I saw this behaviour in 
many macros I wrote, everytime when using declarations like

TH1F test("test",...)

When using the pointer version

TH1F *test = new TH1F(...)

reloading of files works without problems.

Is there anything I missed? 

Best regards,
Volker

-- 
Volker Hejny                    Tel: 02461/616853                      ** 
Institut f. Kernphysik          Fax: 02461/613930                     **
---------------------------------------------------------------- **  ** ---  
Forschungszentrum Juelich GmbH, D-52425 Juelich                    **



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:38 MET