How to change array tree[n] for VC++?

Dear Rooters

In my program I have the following code fragments in many methods:

   TTree *tree[n];
   XCell *cell[n];
   for (Int_t k=0; k<n; k++) {
      cell[k] = 0;
      tree[k] = (TTree*)gDirectory->Get((names[k]).Data());
      tree[k]->SetBranchAddress("DataBranch", &cell[k]);
   }

Although “n” is a variable, this works on both Linux and MacOS X, but I suppose it will not work when trying to compile with VC++.

Thus, I have tried the following substitutions:

   TTree **tree = 0;
   XCell **cell = 0;
   *tree = new TTree[n];
   *cell = new XCell[n];

// or the following:
   TTree   **tree = 0;
   XGCCell **cell = 0;
   *tree = new TTree[n];
   *cell = new XGCCell[n];
   for (Int_t k=0; k<n; k++) {
      tree[k] = new TTree();
      cell[k] = new XGCCell();
   }

Both options compile on my Mac but crash during runtime. Probably, I am making some severe mistake.

Can someone tell me, how I could solve this problem?

Thank you in advance.
Best regards
Christian

If you want to create a dynamic array of pointers, do, eg

TTree **trees = new TTree*[n];What you do has a totally different meaning, you are creating directly n TTree objects.

Rene

Dear Rene

Thank you, I knew I made a severe mistake (it was already late).

Best regards
Christian