Tags

,

//singleton
//JLu@06/22/2014

#include <iostream>

using namespace std;

class Foo
{
public:
	static Foo& Instance()
	{
		static Foo inst;
		return inst;
	}
	
	int Add(int a, int b){return a+b;}
private:	
	Foo(){}
	//two methods below won't cause link errors because they are not never used
	Foo(const Foo&);
	Foo& operator=(const Foo&);
};

int main()
{
	Foo& f = Foo::Instance();
	cout << f.Add(1,2);
	return 0;
}
Advertisements