Apparently, in the Registry of Singletons example, it is still possible to create instances of MySingleton using its default constructor. If we try to avoid that by making the MySingleton() constructor protected instead of public, then the line
static MySingleton theSingleton;
in MySingleton.cpp gives an error at compile time:
error C2248: 'MySingleton::MySingleton': cannot access protected member declared in class 'MySingleton'
See also the TODO in Creational_Patterns/Singleton/registry_of_singletons/main.cpp.
Apparently, in the Registry of Singletons example, it is still possible to create instances of
MySingleton
using its default constructor. If we try to avoid that by making theMySingleton()
constructor protected instead of public, then the linein
MySingleton.cpp
gives an error at compile time:See also the
TODO
inCreational_Patterns/Singleton/registry_of_singletons/main.cpp
.