I have a large simulation written in C++. The main working unit for the simulation is a class that represents neurons. To do its calculations, each instance of the neuron class needs access to the temperature. Each simulation uses tens of thousands of instances of the neuron class and the temperature is the same value for each neuron. For this reason, I would rather not have it be stored as regular member data, so each instance of the neuron class doesn’t have to take up memory storing its own copy. I would ideally store it as a static member variable (or, as a last resort, a global variable). However, I need the temperature to be determined at run-time as user input. Is there any simple way to give the neruon class access to this variable in the manner of static member data?
Share
Just because a variable is static, doesn’t mean that it also needs to be const. See the below code.