Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!julius.cs.uiuc.edu!apple!netcom!teda!ditka!mcdchg!tellab5!balr!clrcom!rmartin From: rmartin@clear.com (Bob Martin) Newsgroups: comp.lang.c++ Subject: Re: Smart pointers and stupid people (was: garbage collection...) Message-ID: <1990Dec26.163210.15650@clear.com> Date: 26 Dec 90 16:32:10 GMT References: <1990Dec20.045909.7681@rice.edu> <3071@lupine.NCD.COM> Organization: Clear Communications, Inc. Lines: 51 In article <3071@lupine.NCD.COM> rfg@NCD.COM (Ron Guilmette) writes: > >Rather than inventing yet another keyword (banned?) how about something >like this: > > class T; > > class smart_pointer_to_T { > /* ... magical stuff, possibly including ref counts, etc. */ > class T* pointer; > public: > smart_pointer_to_T (); > smart_pointer_to_T& operator= (smart_pointer_to_T); > T& operator * (); > }; > > protected class T { > /* ... innards of T ... */ > }; > >The idea here is that once we declare `class T' to be `protected', then >from that point forward (in the compilation) it becomes impossible to >use the type T* in any way, shape, or form. Let me suggest an alternative: class T; class T* { /* ... magical stuff, possibly including ref counts, etc. */ T* pointer; public: T* (); T& operator= (T*); T& operator * (); T& operator [](int); }; I am not sure that I have covered every contigency but the idea is that instead of 'banning' the creation of pointers to certain classes, we create classes which the compiler recognizes to be the pointers to the classes. Then all the dereferencing operations are under the programmer's control regardless of whether anyone else on the project team knows that the pointer is smart. -- +-Robert C. Martin-----+:RRR:::CCC:M:::::M:| Nobody is responsible for | | rmartin@clear.com |:R::R:C::::M:M:M:M:| my words but me. I want | | uunet!clrcom!rmartin |:RRR::C::::M::M::M:| all the credit, and all | +----------------------+:R::R::CCC:M:::::M:| the blame. So there. |