home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!sun-barr!cs.utexas.edu!zaphod.mps.ohio-state.edu!news.acns.nwu.edu!network.ucsd.edu!ucsbcsl!foxtrot!doug
- From: doug@foxtrot.ccmrc.ucsb.edu (Douglas Scott)
- Newsgroups: comp.lang.c++
- Subject: Re: How to keep a member from being deleted thru a pointer?
- Message-ID: <6731@ucsbcsl.ucsb.edu>
- Date: 17 Nov 92 03:55:47 GMT
- References: <1992Nov15.035153.18866@u.washington.edu> <1e567gINNi16@early-bird.think.com>
- Sender: root@ucsbcsl.ucsb.edu
- Distribution: usa
- Organization: Center for Computer Music Research and Composition, UCSB
- Lines: 30
-
- In article <1e567gINNi16@early-bird.think.com> barmar@think.com (Barry Margolin) writes:
- >In article <1992Nov15.035153.18866@u.washington.edu> chuan@stein.u.washington.edu (Chuan Lee) writes:
- >>Now if someone does a
- >> delete c.getItem("a member");
- >>instead of using
- >> c.removeItem("a member");
- >> So how can I prevent that from happening?
- >
- >Make Item's destructor private. Then only members and friends of Item can
- >delete instances of Item.
- >
- >Note, however, that this will also prevent non-members/friends from
- >declaring automatic Item variables, since they would have to invoke the
- >destructor when the variable's scope ends.
-
- I believe you can solve this by doing the following:
-
- const Item* Collection::getItem(const char*) {...}
-
- If I am not mistaken, you cannot call delete on a const return value. Anyone
- else know for sure?
-
-
-
-
- --
- Douglas Scott (805)893-8352
- Center for Computer Music Research and Composition
- University of California, Santa Barbara
- Internet: (NeXTMail ok) <doug@foxtrot.ccmrc.ucsb.edu>
-