I want to declare a global const variable that is defined at runtime. That is, I want to prompt the user for a value and assign it to a const global variable that I don't want to be modified during the execution of the program.
If I wanted a const variable in the main
I could do
int tmp;
cin >> tmp;
const int var = tmp;
But if I want to use a global variable I can't because I have to declare it outside the main
. For context, this is for high performance scientific computing. I want to define a set of physical constants that shouldn't change and that I need to access from anywhere. Is there any way I can do this?