Why gROOT->ProcessLine() executes the default constructor


I have a (at least for me) surprising experience. I have a base class (TBase.C)

[code]class TBase : public TObject
TBase(TString T = “”);

TBase::TBase(TString FName)
printf(“Base: Called with ‘%s’\n”,FName.Data());
and a derived class (TDerived.C)

[code]class TDerived : public TBase
TDerived(TString T = “”);

TDerived::TDerived(TString T )
printf(“Derived: Called with ‘%s’\n”,T.Data());
and I made a test script (DerivedTest.C)

{ gROOT->ProcessLine(".x TBase.C"); gROOT->ProcessLine(".x TDerived.C"); TDerived A("Some"); }
The result of this test is

[quote]root [7] .x derivedtest.c
Base: Called with ‘’
(class TBase)125844712
Base: Called with ''
Derived: Called with ‘’
(class TDerived)125843760
Base: Called with 'Some’
Derived: Called with 'Some’
root [8][/quote]
From this output it looks like that the gROOT->ProcessLine() commands also execute the default constructor found in the file, which is not what I expected. (the command
TDerived A(“Some”);
results in last two output lines
Base: Called with 'Some’
Derived: Called with 'Some’
when compiled with (in wy case, Win32 VC 6) compiler).

Is this extra call to the default constructor some kind of ‘extension’ by CINT or is it a bug?


You should use:

{ gROOT->ProcessLine(".L TBase.C"); gROOT->ProcessLine(".L TDerived.C"); TDerived A("Some"); }
The “.x” you used request the execution of a function whose name is the same as the file and with no argument. So “.x TBase.C” is equivalent to

.L TBase.C TBase()