Getting root to display graphs

Hi! So, I’m new to root, and I’m trying to get root to display a graph using the macro

void graph(){
    TF1 f1("f1","sin(x)/x",0.,10.);

but every time I run the macro, the canvas shows up empty. I can use the commands at the root prompt and get it to display the graph, but not from a macro. Can anyone help? I’m trying to run Root 6.16 on a windows 10 machine. Thanks!


BTW. You should learn about the lifetime of “stack-based” and “heap-based” objects in C++.

Thanks, but I don’t follow your second statement. I’m only using the one TF1, so what’s the problem with using draw?

Your “stack-based” TF1 object is automatically deleted when your “graph” function finishes.

Oh, it already goes out of scope, and the canvas doesn’t hold the image? Okay, thanks!