Question on pointer class members

Hi all,

A quick question on using pointers as data members for a class.

I am writing my own classes and integrating them into the root framework.

I have a class as follows:

class MyClass : TObject

TGraph* pointer;

I initialise this pointer to NULL in the constructor. The memory is only allocated if the user decides they want to call a particular method, otherwise I don’t need to allocate the memory.

When I try to write this object to a root file (before the memory is allocated and the pointer is therefore still null) I get warnings.

My question is, what is the appropriate approach for using pointers as data members within root to get well behaved classes. It’s not completely obvious to me from my intital glances through the documentation.


We need a short running example illustrating your problem.
Are you initializing the pointer also in teh default constructor?


Hi Rene,

Thanks for your reponse. Yes, I initialised the pointer to null in the default constructor. The problem actually went away, when I logged out and logged back into my computer so all’s good.