In practices singleton pattern is created with simple static function that returns one local static variable. As long as the instance is static it returns the same variable defined once during first function call.
The confusing part for me is that if I declare normal static function with static local variable in one header file and include that header in two different translation unit when they call that function the function local static variable is constructed twice - each for each translation unit.
The reason is that with static function identifier function linkage is internal so there are two instances of that functions for each translation unit (source file) and thus there are two local instances for that static variable.
My question is why doesn't that same logic apply to singleton pattern? When we declare static function why isn't it internally linked and thus why doesn't it create two instances of local static variable (which by definition is the only singleton instance) ?
singleton main function I'm talking about:
static className& instance() { static className instance; return instance; }