Canvas is created but is empty when should be showing a graph

Hi,

I have generated a series of points in a text file (named RedArray.txt) and would like to plot it on a canvas via ROOT.
When I do the command directly from ROOT, it works perfectly:

But I would like to do that from my C++ file. I’m writing the exact same thing (without forgetting the semicolon of course) on my C++ file, and it runs on ROOT perfectly without any error, but generates an empty canvas.
What should I do ?

Thank you very much!

Google for C++ object lifetime.

So what should I do then?

Your object gets automatically destroyed at the end of its scope inside your macro. Use a pointer.

1 Like

I get this error when I run it with the pointer : “illegal pointer initialization”

TGraph *g = new TGraph(“BlueArray.txt”); // create it on the “heap”

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.