Skip to main content
gamedev.net
🔒 Locked

c++ Struct Question

Started by hahaha Aug 5, 2007 at 9:40 AM 1 replies 1k views
Original Post
hahaha
hahaha
Is there some way i can make sure only one instance of a struct is ever created?
ToohrVyk
ToohrVyk
Yes, it's possible.

struct TheStruct{  static TheStruct & Instance()  {    static TheStruct instance;    return instance;  }private:   TheStruct();  TheStruct(const TheStruct &);};


There's a very high probability that doing this is useless (i.e. you don't need the protection), and a high probability that your design will cause you great pain in a few weeks or months.
fpsgamer
fpsgamer
A singleton or similarly a monostate.

*A monostate allows multiple instances but all instances share the same state.

[edit]

You could probably avoid both however.

[Edited by - fpsgamer on August 5, 2007 10:19:27 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.