Undeclared identifier error

I’m getting an undeclared identifier error while trying to add two histograms. On running the program, canvas open and shuts instantly without showing any histogram nor any error. The error happens only while accessing the variable from root session but no such thing happened when I tried it with the example on Root Primer.

image ___
Please read tips for efficient and successful posting and posting code

ROOT Version: 6.18
Platform: Windows
Compiler: Not Provided

sumHist is local to your macro and cannot be “seen” outside of the function histSum2. Like with any C++ program. Use unnamed macro to be able to access sumHist after the macro execution.

I’m sorry i’m not able to understand fully, how is declaration of sumHist different than that of gaus_1 and gaus_2?

Inside of your macro, add: sumHist->SetName("sumHist");