TFitResultPtr Constructor

Dear rooters,

Happy new year to everyone, and best wished for 2019. Now this is probably a stupid question, but i am trying to create a TFitResultPtr object. Now I know this is actually behaving like a smart pointer (it will take care of tidying up and deleting). Nevertheless, what I would like to do is to create the object in advance and assign it later in the function with respect to external options (eg changing the type of fits and fit options but keeping the pointer always the sane). Although there is a constructor:

TFitResultPtr(int status = -1): fStatus(status), fPointer(0) {};

I cannot seem to be able to create an empty TFitReulstPtr and assign it later, neither in CINT or ACLIC. In particular in CINT i am getting:

Error: Can’t call TFitResultPtr::TFitResultPtr((class TFitResultPtr*)0x311f780) in current scope (tmpfile)(1)
Possible candidates are…
(in TFitResultPtr)
C:\root\bin\libHist.dll -1:-1 0 public: TFitResultPtr TFitResultPtr::TFitResultPtr(int status=-1);
C:\root\bin\libHist.dll -1:-1 0 public: TFitResultPtr TFitResultPtr::TFitResultPtr(TFitResult* p);
C:\root\bin\libHist.dll -1:-1 0 public: TFitResultPtr TFitResultPtr::TFitResultPtr(const TFitResultPtr& rhs);
*** Interpreter error recovered ***

and while compiling in ACLIC:

C:/Users/Luminociter/Desktop/HGTDUtils/Root/HGTDfITS.cxx(78): error C2440: ‘initialisation’ : impossible de convertir de ‘TFitResultPtr *’ en ‘TFitResultPtr’
C:/Users/Luminociter/Desktop/HGTDUtils/Root/HGTDfITS.cxx(78): note: Aucun constructeur n’a pu prendre le type de source, ou la résolution de la surcharge du constructeur était ambiguë
Error in : Compilation failed!

I am trying to create the object the standard way: TFitResultPtr fitResult = new TFitResultPtr();
What am i missing in this case?

Thanks a lot!!!

Your trying to assign a TFitResultPtr* to a TFitResultPtr. So you need to use either
TFitResultPtr* fitResult = new TFitResultPtr();
or simply
TFitResultPtr fitResult;
Since I’m assuming you want to save the result from TH1::Fit which is a TFitResultPtr, the latter is what you’d want.

This shoukd work:

TFitResultPtr assignToMe;
TFitResultPtr *other = ...;
assignToMe = *other;

Hi Vaubee, actually I already tried creating a pointer instead of the object itself before posting the question here. This does not work, which sort of makes sense since TFitResult is already a pointer with implemented an arrow operator. You can create a TFitResult* because the class has the = operator implemented but it has to be assigned to a FitResult when you do that, new will not work in this case.

Hi Axel,
Thanks a lot, this work and i should have though of that, passing through an intermediate object to implement my logic. I actually kinfolk of get now why I cannot create a TFitResult with the new instruction. I guess I should assign it as a pointer to a FitResult (kind of how we do with the smart c++ pointers). Anyway, thanks!!