I am trying to implement the singleton pattern in c++.
static class_test* getinstance()
{
static class_test single_obj;
return &single_obj;
}
If i want to create singleton object i will go with this method.
class_test *c = class_test :: getinstance();
So it is ensured that single object is maintained everytime.
But in the same program i have used the following statement
class_test test;
This also seems to be works. I think it is a violation of singleton pattern.
Is my understanding is correct?
Or the implementation of the singleton pattern is left with hands of programmer?