|
-
April 7th, 2013, 05:56 AM
#5
Re: Constructors in a singleton
 Originally Posted by tkks
Well from what I read, if I will not define a private copy constructor a default one will be automatically created and multiple copies of my singleton could be made via it.
So I defined a private one, but I am not sure whether I should define a const one or a non-const one so as to satisfy the compiler so it will not create a default one.
What do you think?
If you want to avoid the default generated copy constructor (or copy assignment operator), all you need to do is declare it private and do not define it. This way you will get either an access violation error or a linker error when you try to use them somewhere in your code. You did not show the function definitions in your OP, so I assumed all those functions were implemented. Newer compilers also support explicitly deleting the default generated functions, see http://en.wikipedia.org/wiki/C%2B%2B...mber_functions.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|