GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 16-May-2008, 03:35
vicky_brsh vicky_brsh is offline
New Member
 
Join Date: Dec 2007
Posts: 22
vicky_brsh has a little shameless behaviour in the past

How to make both Base and Derived class a Singleton


Hi All,

I know how to make a class as Singleton. Example as below.

CPP / C++ / C Code:
     #include <iostream>
     using namespace std;

     class Test {
       public :
              static Test & GetInstance()
               {
                     if (obj == NULL)
                       obj = new Test;
                   return obj;
                  }
         private :
                 Test(Test & test){} // Disable Copy Constructor
                 Test & operator =(Test & test){}  // disable the assignment operator
                static Test *obj;
            
      
          };

   int main()
  {
        Test *objTest = Test::GetInstance();
        return 1;
   }

Now suppose i have to derive a class from Test and want to create an object to the derived class which should be a Singleton object.

How can i achieve this.

Can any one help me to solve this problem


Thanks and Regards
Vikram
Last edited by LuciWiz : 16-May-2008 at 04:10. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
 

Recent GIDBlogLast Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help With Class Inhertance doom1992 CPP / C++ Forum 5 22-Oct-2007 20:06
Classes and allocating memory BlueFireCO. CPP / C++ Forum 13 26-Jul-2007 20:31
help with stl vector of non-homogenous derived objects mpakala CPP / C++ Forum 2 12-Jan-2007 08:51
Accessing constructors of a base class explicitly in the derived class nethravathi.mn CPP / C++ Forum 1 27-Sep-2006 17:13
References to base class to access derived class only members mirizar CPP / C++ Forum 3 03-Dec-2005 20:40

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:05.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.