SetBranchAddress(branchname, this) or similar

dear friends,
I wanted to write a small class which should act both as a container class and as a steering
class for data I/O.

the idea is the following:

class myclass : public TObject {

   void ReadData(Char_t *filename);
   void WriteData(Char_t *filename);

   Int_t data;


I could implement the WriteData function

void myclass::WriteData(Char_t *filename) {

   TFile *file.......
   TTree *tree.......
   tree->SetBranch("branchname", this);


whereas I don’t know if I can actually implement the ReadData function. Indeed, I should use the call

tree->SetBranchAddress("branchname", &this);

but like this the code doesn’t compile because of &this.

do you have any suggestion?
many many thanks.
best regards,


For now, you must declare a pointer and assigned the value of this to it:myclass *ptr = 0; ptr = this; tree->SetBranchAddress("branchname", &ptr);where ‘ptr’ can be either a local variable (if the GetEntry are all done in the same function and if you call ResetBranchAddresses at the end of the function) or a data member of myclass (marked transient).