Thread: Singleton Class error

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Anirban Ghosh
    Join Date
    Jan 2006
    Posts
    278

    Singleton Class error

    Code:
    #include <iostream>
    
    using namespace std;
    
    class Myclass
    {
    
    	private:	
    	static int count;
    	
    	
    	Myclass()
    	{
    
    	}
    
    
    	
    	
    	public:
    
    	static Myclass* CreateInstance();
    
    	~Myclass()
    	{
    		count--;
    
    	}
    };
    
     Myclass* Myclass::CreateInstance()
    	{
    		Myclass *ptr = NULL;		
    		if(!count)
    		{
    			count++;
    			ptr = new Myclass;
    			return( ptr );
    		}
    		else
    		{
    			cout << "\nClass Instantiation no possible!\n";
    			return NULL;
    		}
    	}
    
    
    int main()
    {
    		Myclass *ob = Myclass :: CreateInstance();
    
    		return 0;
    }
    ERROR MESSAGE..

    Code:
    /tmp/ccPSDOBz.o: In function `Myclass::CreateInstance()':
    test.cpp:(.text+0x13): undefined reference to `Myclass::count'
    test.cpp:(.text+0x1d): undefined reference to `Myclass::count'
    test.cpp:(.text+0x26): undefined reference to `Myclass::count'
    collect2: ld returned 1 exit status
    Last edited by anirban; 10-27-2010 at 11:02 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Getting other processes class names
    By Hawkin in forum Windows Programming
    Replies: 3
    Last Post: 03-20-2008, 04:02 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM