Thread: Singleton Problems..

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    102

    Smile Singleton Problems..

    Hey all I have recently made a Singleton class directly from a book I recently purchased, Here it is:

    Code:
    class Singleton
    {
    public:
    	 static void Create();
    	 static void Destroy();
    	 
    	 static Singleton * GetInstance()
    	 {
     	   		return s_pInstance;
    	 }
    	 
    	 static int GetNum();
    	   		 
    protected:
    		static Singleton* s_pInstance;
    		
    		//Hidden Constructor
    		Singleton();
    };
    
    // Implementation
    Singleton* Singleton::s_pInstance = NULL;
    
    void Singleton::Create()
    {
     	   if(!s_pInstance)
    		   s_pInstance = new Singleton;
    		
    		   
    }
    
    void Singleton::Destroy()
    {
     	   delete s_pInstance;
     	   s_pInstance = NULL;
     	   
    }
    However if I inherit from it with another class, I am not able to call any of it's own member functions, because of the Singleton Pointer.
    My Book doesn't give much information on it, and I might be able to find a way, but I don't want to make many changes without being sure there isn't a better way.
    Does any one have a suggestions?
    PS: I'm a pretty new programmed, and I appreciate any help.

    I am currently using the Dev C++ Software Compiler. The error message returned is..
    Class Singleton has no member function named (Function).
    Last edited by JJFMJR; 04-09-2007 at 05:05 PM. Reason: Additional Information

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Singleton template problem
    By cloudy in forum C++ Programming
    Replies: 14
    Last Post: 01-11-2009, 05:40 AM
  2. How To Derive from a singleton
    By appleGuy in forum C++ Programming
    Replies: 8
    Last Post: 03-24-2007, 01:55 PM
  3. Thread-safe singleton.
    By Hulag in forum C++ Programming
    Replies: 3
    Last Post: 06-14-2006, 10:45 AM
  4. Singleton problems
    By techrolla in forum C++ Programming
    Replies: 16
    Last Post: 01-02-2005, 04:05 PM
  5. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM