Re: TClonesArray and derived classes

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Thu, 18 Nov 2010 09:33:38 -0600


Hi,

> where the TClonesArray was initialized using the base class name.

A TClonesArray must be filled with only object of a single type which is assume to be the one the TClonesArray was initialized with.

> I have then filled a TClonesArray with objects of the derived class type,

The derived part will be most ignored (it will not be stored nor restored).

> What should I pay attention to when doing such operations, in order to be sure that the overloaded method is called correctly?

You need to initialize the TClonesArray with the exact type you will use to fill it.

Cheers,
Philippe.

On 11/16/10 6:40 PM, Alberto Pulvirenti wrote:
> Dear all,
>
> I have built a classe deriving from TObject, which in turn is a base class for some other derived ones.
> I have then filled a TClonesArray with objects of the derived class type, where the TClonesArray was initialized using the base
> class name.
> This TClonesArray is looped by my code, which retrieves all contained objects and calls a method which is defined in the base
> class and overloaded by the derived classes.
> Unfortunately, I had the impression that during this loop, instead of calling the overloaded function (that defined in the derived
> classes), the code calls the implementation of the base class.
>
> What should I pay attention to when doing such operations, in order to be sure that the overloaded method is called correctly?
>
> Ciao
>
> Alberto
>
Received on Thu Nov 18 2010 - 16:34:53 CET

This archive was generated by hypermail 2.2.0 : Fri Nov 19 2010 - 05:50:02 CET