Only 1 Object of the C++ class ??

ZulfiqarKhan

Beta member
Messages
1
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.
 
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.
 
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.
 
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.
 
Back
Top Bottom