Example for Singleton usage
- Author
- woelk
#include <Base/Common/Singleton.hh>
using namespace BIAS;
using namespace std;
public:
double data;
MyClass() : data(0) {}
MyClass(const MyClass &a) : data(a.data) {}
MyClass& operator=(const MyClass& a) { data = a.data; return *this; }
};
void function()
{
MyClassSingleton::GetInstance()->data = 5;
}
int main(int argc, char *argv[])
{
cout << "initial data: " << MyClassSingleton::GetInstance()->data << endl;
function();
cout << "after function: " << MyClassSingleton::GetInstance()->data << endl;
cout << "accessing Singleton<MyClass> is identical to MyClassSingleton: "
return 0;
}