Re: TClonesArray typecasting

From: Kevin Lynch <krlynch_at_bu.edu>
Date: Tue, 14 Nov 2006 13:51:43 -0500


George Locke wrote:
> Hey all,
>
> This is a simple question. i'm using the latest root (5.13.04) on
> windows 2000, compiling with visual C++ 2005 (aka msvc 8).
>
> i filled a TClonesArray with TH1F's, and now i want to fill the histograms.
>
> this code returns the error "'Fill' : is not a member of 'TObject'"
> (TH1F *) bigArr[chan]->Fill(j, value);
>
> what should i write instead?
>

You probably need some extra parens (untested...)

( (TH1F*)bigArr[chan] )->Fill(j, value);

[] and -> bind more tightly than a Unary (C-style) cast in the C++ grammar, so your original line is probably being interpreted the same as the following snippet:

(TH1F*) ( (bigArr[chan]) -> Fill(j,value) )

Which as you've discovered, fails because "Fill" is not a member of "TObject" (here, bigArr[chan]).

> Thanks for answering such a simple question,
> George

-- 
-------------------------------------------------------------------------------
Kevin Lynch				voice:	(617) 353-6025
Physics Department			Fax: (617) 353-9393
Boston University			office:	 PRB-361
590 Commonwealth Ave.			e-mail:	 krlynch_at_bu.edu
Boston, MA 02215 USA			http://budoe.bu.edu/~krlynch
-------------------------------------------------------------------------------
Received on Tue Nov 14 2006 - 19:52:02 MET

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:32:02 MET