If I do not want to allow anyone to create an instance of my class other than my static functions (I think this is called singleton / factory?), Is it enough to make it the default constructor or to do it? I also need to explicitly define and make the copy constructor and operator private assignment?
Yes, I would do all 3 of these manager functions. If not, you do not want to have access to the copy constructor. For example, this is valid:
Singleton * s; Singleton copy( *s );
So do something like:
class Singleton { private: Singleton(); Singleton(const Singleton &); Singleton & operator = (const Singleton &); };
constuctor private factory. singleton factory.boost , , , , , , . , , , , .
, . , :
MyClass newObject = your_singleton_of_type_MyClass;
, . , .
If you need only one instance, then yes, the copy constructor should be private. The assignment operator should not matter because it will be impossible to use.
Source: https://habr.com/ru/post/1772952/More articles:pylons: model-level data validation - validationCreating a cross-process function pointer - c ++copy production database to capistrano stage - ruby-on-railsWhy does setting a default make this function private? - closureshttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1772951/alternatives-to-jpegreadheader-libjpeg&usg=ALkJrhhtyQ_jq3tJfQZFrba7VtHULYXFOQUsefulness of loading instances in OO PHP? - objectBest practice for uploading .Net project to web server - version-controlWhat is the difference between "$ .FunctionName ()" and "FunctionName ()"? - javascriptWhen I click, I want to add the value of the a-tag to the input field - javascriptsingle quote in file name - javascript, php - javascriptAll Articles