Here is the relevant part of my program
extern const std::map<std::string, int> constMap;
std::map<std::string, int> initConstMap()
{
}
const std::map<std::string, int> constMap = initConstMap();
\\ main.cpp
...
for (int i = 0, n = LOTS_OF TIMES; i < n; ++i){
doSomethingWith(constMap[i]);
}
...
I wonder if every time I use the constMap variable during my main program, will it run the initConstMap function every time or not? The const map is obviously constant and therefore does not need to be initialized many times. (* Note that the main cpp is a custom-made example, this is not what my program does. I am simply simplifying things for the sake of the question).
source
share