Computer Forums

Computer Forums (http://www.computerforums.org/forums/)
-   Programming (http://www.computerforums.org/forums/programming/)
-   -   Only 1 Object of the C++ class ?? (http://www.computerforums.org/forums/programming/only-1-object-c-class-126584.html)

ZulfiqarKhan 08-04-2005 08:31 AM

Only 1 Object of the C++ class ??
 
Is it possible to create a class in C++ of which only 1 object can be created ?? ( Excatly 1 not more than 1 ). It should not allow more than 1 object to be created.

Argon 08-04-2005 09:42 AM

well the whole point of objects is to make multiple instances of them. If you want to write a program that only allows users to create 1 instance of an object at a time, then that has to be mediated by the program itself, not by the object class. You could always hardcode it into the main class of your program though.

Tulsileaf 08-04-2005 10:38 AM

Re: Only 1 Object of the C++ class ??
 
actually, you can make such an object by having a static boolean flag private member of the class set to false if the object has not been made and true if it has. Then just have the constructor check this flag and not create the object if it has already been made.

hextcomm 08-21-2005 06:40 PM

Good Day
 
Hello, we are working on a project, we really need Programmers (all) to assist us,the primary laguages are C, C++ and C#, this project
is a free program which is to run in the background of your Operating System and
to monitor processes without hogging much system rsources and to automatically shut down suspicous processes,
if you are interested in joining as a voluntary staff member, please contact me at hextcomm@yahoo.com.

Thank You.


All times are GMT -5. The time now is 05:40 PM.

Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0