TTimeStamp bug?

Hi,

I garnished the TTimeStamp class to be TimeStamp class.( pls see codes below). The problem is if I do
TimeStamp x;
TimeStamp y(x);

x.Print()
y.Print()

I got very different results and I expect them the same. My codes looks fine to me. Thank for your helps.

#ifndef TIMESTAMP_H
#define TIMESTAMP_H

#ifndef ROOT_TTIMESTAMP
#include "TTimeStamp.h"
#endif


class TimeStamp: public TTimeStamp{

private:
	
public:
    TimeStamp();
    TimeStamp(const timespec_t& ts);
    TimeStamp(const TimeStamp&);
    TimeStamp(time_t t, Int_t nsec);
    TimeStamp(UInt_t tloc, Bool_t isUTC = kTRUE, Int_t secOffset = 0, Bool_t dosDate = kFALSE);
    TimeStamp(UInt_t date, UInt_t time, UInt_t nsec, Bool_t isUTC = kTRUE, Int_t secOffset = 0);
    TimeStamp(UInt_t year, UInt_t month, UInt_t day, UInt_t hour, UInt_t min, UInt_t sec, UInt_t nsec = 0, Bool_t isUTC = kTRUE, Int_t secOffset = 0);

    ~TimeStamp();


    Bool_t operator ==(const TimeStamp& b);

    Bool_t operator <(const TimeStamp& b);
  
    ClassDef(TimeStamp,1);
};


#endif



#include "TimeStamp.h"

#if !defined(__CINT__)
	ClassImp(TimeStamp);
#endif


TimeStamp::TimeStamp():TTimeStamp(){};

TimeStamp::TimeStamp(const timespec_t& ts):TTimeStamp(ts){};

TimeStamp::TimeStamp(const TimeStamp& rhs):TTimeStamp(rhs){};

TimeStamp::TimeStamp(time_t t, Int_t nsec):TTimeStamp(t,nsec){};
TimeStamp::TimeStamp(UInt_t tloc, Bool_t isUTC, Int_t secOffset, Bool_t dosDate):TTimeStamp(tloc,isUTC,secOffset,dosDate){};  
TimeStamp::TimeStamp(UInt_t date, UInt_t time, UInt_t nsec, Bool_t isUTC , Int_t secOffset ):
            TTimeStamp(date,time,nsec,isUTC,secOffset){};
TimeStamp::TimeStamp(UInt_t year, UInt_t month, UInt_t day, UInt_t hour, UInt_t min, UInt_t sec, UInt_t nsec, Bool_t isUTC, Int_t secOffset ):
            TTimeStamp(year,month,day,hour,min,sec,nsec,isUTC,secOffset){}; 
TimeStamp::~TimeStamp(){};


Bool_t TimeStamp::operator ==(const TimeStamp& b) {
       return this->GetDate()==b.GetDate() && this->GetTime()== b.GetTime() && this->GetNanoSec()== b.GetNanoSec();
};

Bool_t TimeStamp::operator <(const TimeStamp& b) {
       return  this->GetDate()<b.GetDate() || this->GetTime()< b.GetTime() || this->GetNanoSec()< b.GetNanoSec();
};

cheers,

gma

Hi,

You example works nicely if compiled (.L TimeStamp.C+) but fails if it is interpreted … which is somewhat expected since, in general, you can not safely derive an interpreted class from a compiled class.

Cheers,
Philippe.

Philippe,
Thanks. Would you mind explaining more why I can not safely derive an interpreted class from a compiled class? I was assuming no difference between script or binary code except speed.

regards,

gma

Hi,

In order to implement the virtual function lookup most C++ implementation used what’s call a virtual table, in essence an array of pointer to member functions. This table is extremely compiler implementation dependent. This table is use for all access to the virtual function from the compile code. An interpreted class can not (unless we work very hard at it with lost of compiler dependent code or used ‘compiled’ stub classes) ‘registered’ the ‘interpreted’ implementation of the virtual function overload into this virtual table.

Cheers,
Philippe.

Hi, Philippe,

Thanks. This makes sense. I did not realized that virtual functions create this kind of problem for interpreter until you explained to me.

cheers,

gma