.Draw() - appears the empty window, why?


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.14.00
Platform: linuxmint19.3

Hello!
I am novice in root and I`m trying to run macros .L macros.cpp
{
TF1 f1(“f1”,“sin(x)/x”,0.,10.);
f1.Draw();
}
and it is successfully.
But if I try run main: .L macros.cpp main()
int main() {
TF1 f1(“f1”,“sin(x)/x”,0,10);
f1.Draw();
return 0;
}

  • appears empty window (canvas) without any graphs… Why?
    I need to write cpp-program using root, but in this case I shall try use macros without functions?
    Can somebody help with this problem?

Because f1 is local to the named macro main and is deleted when exiting main. Make it a pointer and it will work:

int main() {
   auto f1 = new TF1("f1","sin(x)/x",0,10);
   f1->Draw();
   return 0;
}

Thanks you!

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