November 12th, 2012, 02:51 PM
I have a larger project here. It mainly consists of one window and a set of classes. At runtime, the class instances have to know about each other, ie class instance A might somehow use the class instance B, with which it is associated. I have simply wrapped all classes in one "Instance" class, and have declared a global function, which returns a pointer to the "Instance" class and thus allows the classes to use each other.
This works well as "Instance" is a singleton.
Now, however, i want to launch two windows in my program and would thus need TWO instances of the "instance" class!
The concept fails. (ok, it wasnt pretty anyways...)
A lot of the classes from above are Storage classes, ie classes whose main task it is to store a set of values (or whatever). Internally, it of course uses vectors/maps/lists/... to store the content, however the interface it provides may be more advanced.
FOr example: A story may consist of several Scenes. The storage class would store instances of the struct "Scene", while providing an interface to work with more abstract problems, like overlapping or overall coverage. This is just an example.
What would be an alternative/better approach here?
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!