Mail Archives: djgpp/1997/06/28/11:02:52
In article <5p0epd$gtj AT netlab DOT cs DOT rpi DOT edu> on 27 Jun 1997 09:22:15 -
0400, scochran AT shoalsnet DOT com says...
> In C++ I've run into yet another brick wall. I have a class called arena
> that is a 50x50 arena for obstacles and robots (for now anyway). I'm
> running into problems because I only want to have one copy of the arena and
> multiple copies of the robots or whatever I want to put.
You need to get the book "Design Patterns" by Gamma, Helm, Vlissedes
and Johnson (Addison-Wesley, ISBN 0-201-63361-2). The book contains
many useful patterns that come up in designing classes (a pattern
being a way in which classes interact). One of the patterns is called
a "singleton" - you limit the number of instances of a particular
object to one per application.
Basically, you declare the constructors (default, copy) and assignment
operator private, and provide a static pointer to the class. You also
provide a public function to allow access to the class.
If I told you any more details, then you would not get the book and
you would deprive yourself of a great reference tool :-)
--
Jim Hyslop
There are two kinds of people in this world: those who think there are
two kinds of people, and those who don't.
Don't pass on that email about someone dying of cancer or a "new
super-powerful computer virus" until you check out the Internet Hoax
page http://ciac.llnl.gov/ciac/CIACHoaxes.html first!
[ Send an empty e-mail to c++-help AT netlab DOT cs DOT rpi DOT edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
- Raw text -