lundi 29 mai 2017

How to ensure a specific class only can create an instance of another class?

How can I restrict the instantiation of a class from only within a specific class? I don't want to restrict it within a single file, so anonymous namespace is not an option for me. Please note that I want to make the declaration of the to-be-restricted class visible to the entire world, just that only one specific candidate from the entire world can only instantiate and access it. How to achieve this in c++?

Aucun commentaire:

Enregistrer un commentaire