From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,604e0f87aa06eab6 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-03-26 10:40:41 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!cyclone.bc.net!tdsnet-transit!newspeer.tds.net!newspeer.radix.net!uunet!ash.uu.net!spool0901.news.uu.net!spool0900.news.uu.net!reader0902.news.uu.net!not-for-mail Date: Wed, 26 Mar 2003 13:40:28 -0500 From: Hyman Rosen User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4a) Gecko/20030313 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Imitation is the sincerest form of flattery References: <1048524746.273345@master.nyc.kbcfp.com> <1048530794.5794@master.nyc.kbcfp.com> <1048623730.801824@master.nyc.kbcfp.com> <8j838v81tn0t2ft4locfphs6tg6t7e1lvb@4ax.com> <1048691202.136151@master.nyc.kbcfp.com> <1ij38vsm381u560p0rmhenia606ggo9jpv@4ax.com> <1048698047.463797@master.nyc.kbcfp.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Organization: KBC Financial Products Message-ID: <1048704028.300485@master.nyc.kbcfp.com> Cache-Post-Path: master.nyc.kbcfp.com!unknown@nightcrawler.nyc.kbcfp.com X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) NNTP-Posting-Host: 204.253.250.10 X-Trace: 1048704030 reader2.ash.ops.us.uu.net 20089 204.253.250.10 Xref: archiver1.google.com comp.lang.ada:35735 Date: 2003-03-26T13:40:28-05:00 List-Id: Bill Findlay wrote: > could you explain what is going on in this rather obscure-looking code, > for the sake of C++ non-gurus like me? The class funky_array can be treated like an array wrt indexing: funky_array fa; fa[7] = 10; This works because funky_array declares an 'operator[]', an overloaded operator which is invoked through use of []. Instead of returning the element itself, the indexing operator returns an index_proxy object, which holds a reference to the funky_array object itself and the index. This proxy object has an 'operator Element &' member, that is, a user-defined conversion operator from itself to a reference to an Element (int, in our case). When you try to use the proxy object in a place where an Element is expected, the compiler will use the conversion operator to convert the proxy to an Element.