Computer Forums

Computer Forums (
-   Programming (
-   -   Only 1 Object of the C++ class ?? (

ZulfiqarKhan 08-04-2005 09: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 10: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 11: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 07: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

Thank You.

All times are GMT -5. The time now is 11:12 PM.

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