Class type : cint and g++ gives different results

Dear rooters,

I don’t know it is the right place to post this since it might be a pure C++ problem, but it strongly correlated to ROOT based code.
I wrote a class (let’s call it A) that contains as member another class B (that inherit from TObject).
In A I create a getter that point to the member fB of type B .

B* GetB() { return (B*)fB; }

fB is of course a B*
Note that in the constructor of A I call fB = new B()

Now here is my problem : I instantiate the class A and use the getter to obtain a pointer on B

A temp = new A() ; cout << temp->GetB() << endl ;
The result is a non null. If now I try (since B inherit from TObject):

[li]returns the right information (especially the name of the class) if called in CINT (after compilation)[/li]
[li]does not return the right information if the code is compiled outside ROOT. In fact return informations about another member of the class A[/li][/ul]

Can you point at any test I can perform to understand what’s going on ?


Hi Julien,

What is the ‘type’ of fB itself (not what it points)? I.e. why did you have to add the C style cast in the getter. Depending the answer, it might be plausible that the solution is to use:B* GetB() { return dynamic_cast<B*>(fB); }Also to understand the problem you may want to run valgrind on your compiled code.