Error: redefinition of a variable

When I try to load the same code a second time in the terminal, it shows the following error.

My understanding is that if you create a variable using “new”, the memory is stored in a heap so you have to use delete command to free the space. However, I have defined the variable normally so it should be stored in stack memory and should be freed after the program ends.

How can I execute my code without getting the following error? Thank you.

Hi,
this was a limitation of the ROOT interpreter until recently (stemming from the fact that C++ does not like redefinition of variables).

In ROOT v6.22 (or maybe already in v6.20) the situation is greatly improved. What ROOT version are you on?

Cheers,
Enrico

My ROOT version is 6.16/00.

Yep,
so that’s it. Please check https://root.cern/install for available ways to upgrade to a more recent ROOT version.

Cheers,
Enrico