Functions with Objects from External Macro

I am trying to load a macro which is outside and would like to pass say a histogram object to it. How can I do it?

Main macro :

#include <TH1D.h>

using namespace std()

void testMacro(){

TH1D *h = new TH1D("h", "", 10, -3, 3);
h->FillRandom("gaus", 1000);

gROOT->ProcessLine(".L extMacro.C+")
extMacro(h); // Fails here
}

External Macro :
#include <TH1D.h>
#include <iostream>
void extMacro(TH1D *h){
  std::cout << h->GetSize() << endl;
}

.L testMacro.C++ // Successful if the line extMacro(h) is commented out

Hi,

assuming that you are using a ROOT6 version, the proper way to handle this case is:

// Add here the include of the external macro
#include "extMacro.C"

void testMacro(){

TH1D *h = new TH1D("h", "", 10, -3, 3);
h->FillRandom("gaus", 1000);

// gROOT->ProcessLine(".L extMacro.C+") <- not needed anymore
extMacro(h); // Fails here
}

Cheers,
Danilo