Path: utzoo!mnetor!tmsoft!torsqnt!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!cs.utexas.edu!usc!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 (my reactions and a new idea) Message-ID: <1991Jan19.190403.24325@clear.com> Date: 19 Jan 91 19:04:03 GMT References: <3348@lupine.NCD.COM> Organization: Clear Communications, Inc. Lines: 44 In article <3348@lupine.NCD.COM> rfg@lupine.ncd.com (Ron Guilmette) writes: >Now for my detailed comments on the "smart pointer problem" discussion >so far. (This is where it really starts to get biased! :-) >-------------------------------------------------------------------------- > >The solution proposed by Bob Martin and (independently) also by Jeremy >Grodberg to allow the type T* to be treated like a class (which can >be declared and which can have member functions and operators defined >for it) is clever and I had myself considered it, however I fear that >Bjarne will never like it. The reason? Well, it makes the language >"mutable" (in Stroustrup's terms). One early (and related) idea >which I had some time ago for solving this "smart pointer" problem >was to allow stuff like: > > T*& operator= (T*, T*&); > T operator* (T*); > >In effect, I wanted to let the user just redefine the meaning of = and >(unary) * for plain old pointer types. If you could do that, then you >could be in complete control of all operations done with stupid pointers. >That idea was almost the same as allowing: > > class T* { > public: > T*& operator= (T*&); > T operator* (); > }; > >But in both cases, you are allowing the user to change the existing >meaning of things whose meaning is already well defined in the language >(e.g. the meaning of unary * when applied to a pointer type value). But don't the unary operator& and operator* already violate this rule of mutability? ARM 13.4 implies that there is no return type restriction on these operators. So by using an Y operator*(X*) you "Change the meaning of unary * when applied to a pointer type value." Can you elaborate more on this? -- +-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. |