I have a static instance of a class defined in a function with {} initialiser in C++
Let us say in the function I increment a counter defined in that class.
In the constructor I have a print statement.
The print statement gets displayed first time the function gets called (not when main() starts) On subsequent calls of that function the constructor does not get called.
How does the function know that the initialisation code only happens on the first call and not subsequent? The only way I can think of is that there is some code that must check a flag to see if the constructor has been called and the flag is not part of the class but a hidden one.
Look forward to learning how it magically works.