fork download
  1. #include <iostream>
  2. class cMySingleton{
  3. private:
  4. static bool bInstantiated;
  5. int mInt;
  6. cMySingleton(){
  7. mInt=0;
  8. }
  9. public:
  10. cMySingleton(int c){
  11. if (bInstantiated){
  12. std::cout << "you can only instantiated once";
  13. }
  14. else {
  15. cMySingleton();
  16. mInt=c;
  17. }
  18. }
  19. };
  20. bool cMySingleton::bInstantiated = 3;
  21. int main () {
  22.  
  23. cMySingleton s(5);
  24. cMySingleton t(6);
  25. }
  26.  
Success #stdin #stdout 0s 2928KB
stdin
Standard input is empty
stdout
you can only instantiated onceyou can only instantiated once