a question about singletons
Posted: Wed Aug 06, 2008 4:07 am
well i have adopted the use of singletons for my factory in my game engine. it really makes alot of things easier.
i have started writing another small program for my own use, and it is using C. now, i was wondering,
with a singleton class you would do this to get its instance:
now i rememberd something from when i started with C. this is pretty much a singleton, but MUCH easier to implement.
definition
and usage
my question is, i have been flamed for using this coding technique before. i know it seems wrong coming from a C++ enviorment, but what is wrong with using this method? i don't see any issue other than sloppyness, but that doesnt matter in a project with minimal lines of code...
thanks!
i have started writing another small program for my own use, and it is using C. now, i was wondering,
with a singleton class you would do this to get its instance:
Code: Select all
myclass theSingleton = myclass::getinstance();
definition
Code: Select all
struct myclass
{
int somevar;
void somefunction () { instance.somevar = 1; };
} instance; /* <-- */
and usage
Code: Select all
instance.somefunction ();
thanks!