Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!uunet!microsoft!jimad From: jimad@microsoft.UUCP (Jim ADCOCK) Newsgroups: comp.lang.c++ Subject: Re: Overloaded operator dot? Message-ID: <71437@microsoft.UUCP> Date: 21 Mar 91 19:41:18 GMT References: <11152@jarthur.Claremont.EDU> <624@taumet.com> <1991Mar17.184122.717@mathcs.sjsu.edu> Reply-To: jimad@microsoft.UUCP (Jim ADCOCK) Organization: Microsoft Corp., Redmond WA Lines: 119 In article <1991Mar17.184122.717@mathcs.sjsu.edu> horstman@mathcs.sjsu.edu (Cay Horstmann) writes: |The most important question is of course: Does it solve any problems? Recently |it was generally agreed that it would be useful for defining an access class |which can be both an lvalue and an rvalue. Is anyone aware of another use for |it? Overloaded operator dot is for all practical purposes necessary in order to be able to make "smart reference classes" just as today one can make "smart pointer classes." The question then becomes why would one prefer to use "smart reference classes" over "smart pointer classes" ??? [I use the term "smart" here in a very loose sense. By a "smart pointer class" I really mean any class that is implemented to act as if it is a pointer -- whether that class does anything intelligent, or simply forwards all requests to the pointed-at object is immaterial to my discussion. The same holds true for "smart reference classes"] Two situation where "smart reference classes" are clearly preferrable to "smart pointer classes" are: 1) when such an object has to act like a value, and 2) when such an object has to act like a normal object. [A simpler way to say this would be to state that smart reference classes are always preferred to smart pointer classes -- except when you're trying to make a pointer class -- but that sounds like a circular argument.] Lets see how this might be used. First case is when a smart reference class has to act like a value. Matrices have been a hot topic recently -- let's consider how one would make a reference counted matrices class. Lets call the class that implements the actual storage requirements and reference count of the matrices the ActualMatrix class, and have the smart reference class simply called Matrix -- in order to hide implementation details from the end users. We want to be able to write code like this: Matrix ReadANewMatrix(int row, int col) { Matrix A(row, col); for (int i=0; i, and is necessary if you want to be able to use templates to make smart reference classes.