Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!uunet!microsoft!jimad From: jimad@microsoft.UUCP (Jim ADCOCK) Newsgroups: comp.lang.c++ Subject: Re: Distinguishing lvalue/rvalue operator[] Message-ID: <71126@microsoft.UUCP> Date: 7 Mar 91 20:24:52 GMT References: <1991Mar3.202134.17812@mathcs.sjsu.edu> <1991Mar4.031900.16827@world.std.com> Reply-To: jimad@microsoft.UUCP (Jim ADCOCK) Organization: Microsoft Corp., Redmond WA Lines: 38 In article <1991Mar4.031900.16827@world.std.com> wmm@world.std.com (William M Miller) writes: |> I just tried this out and it broke my code right away. The line |> a[i].print(); |> didn't compile--print() is not a member function of Access! | |So what's the big deal? Just add an inline Access::print() member function |that forwards the call to X::print(). Admittedly, that could be a pain if |you're working with an X that has dozens of members (and, at least for |current compilers, there will be some runtime overhead involved in the |initialization of references to data members that are to be accessed |transparently), but I haven't seen anything you want to do that's |prohibitively hard or impossible to do in the current language. In my |experience, this problem doesn't arise all that often, and if you do run |into it all the time, it would be pretty straightforward to program a filter |that automatically produced an Access class for a given X. Yes, you can do this using a C-preprocessor macro hack, or an external tool, but the resulting code becomes a pain to debug and maintain. Today, if people want to add N "smart array" classes each with about M methods in the element class, then people have O(M*N) amount of programming to write . -- unless they hack it using the preprocessor or some other tool to write it. With overloadable operator dot, this effort becomes a much more reasonable O(N) programming effort. And [ off the top of my head ] with templates and overloadable operator dot, it would seem that writing smart array classes becomes an O(1) effort -- one template smart array class can be written that also defines the requisite smart reference class. Thus, with templates and overloadable operator dot, I'd say C++ "supports" smart array classes. Without overloadable operator dot, I'd say C++ doesn't support smart array classes, but rather forces programmers to go outside the language. Seems to me this is reason enough alone to add overloadable operator dot to the language. To me, overloadable operator dot seems like a cheap and easy fix to a lot of programming problems. -- Not to mention adding overloadable operator dot just removes one exceptional case from the language.