delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/06/28/11:02:52

From: jim DOT hyslop AT leitch DOT com (Jim Hyslop)
Newsgroups: comp.lang.c++,comp.lang.c++.moderated,comp.os.msdos.djgpp
Subject: Re: Using one copy of class for many other classes
Date: 27 Jun 1997 13:44:32 -0400
Organization: Leitch Technology Int.
Lines: 32
Sender: cppmods AT netlab DOT cs DOT rpi DOT edu
Approved: dietmar DOT kuehl AT uni-konstanz DOT de
Message-ID: <5p0u48$kvv@netlab.cs.rpi.edu>
References: <5p0epd$gtj AT netlab DOT cs DOT rpi DOT edu>
NNTP-Posting-Host: netlab.cs.rpi.edu
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019