Hi All,

Please suggest me the link or sample code for the singleton method.

1) Need to create single instance and need to use that instance in entire project.
2) Should not allow to create new instance.
Code:
#include <stdio.h>
#include <iostream>
using namespace std;
class Sample
{
	private:
	int test;
	public:
	int setValue(int a)
	{
		test=a;
	}

	int getValue()
	{
		cout<<"test value = "<<test;
	}
};
class CMySingleton
{


	private:
  	CMySingleton() {};   
	static Sample *singleton;

	public:
  	static Sample* Instance()
  	{
		singleton=new Sample();
	    	return singleton;
  	}



};
int main()
{
	Sample *obj=CMySingleton::Instance();
	cout<<"\n "<<&obj;
	Sample *obj1=CMySingleton::Instance();
	cout<<"\n "<<&obj1;
	return 0;

}
It throws error

/tmp/ccFuSDhv.o: In function `CMySingleton::Instance()':
singleton.cpp.text._ZN12CMySingleton8InstanceEv[CMySingleton::Instance()]+0x17): undefined reference to `CMySingleton::singleton'
singleton.cpp.text._ZN12CMySingleton8InstanceEv[CMySingleton::Instance()]+0x1e): undefined reference to `CMySingleton::singleton'

Thanks
-Viswa