Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!gem.mps.ohio-state.edu!apple!usc!orion.oac.uci.edu!uci-ics!news From: schmidt@glacier.ics.uci.edu (Doug Schmidt) Newsgroups: gnu.g++.bug Subject: Re: G++ 1.36 problem? Message-ID: <1989Oct16.222036.20829@paris.ics.uci.edu> Date: 16 Oct 89 22:20:36 GMT References: <46991@bbn.COM> Sender: news@paris.ics.uci.edu (Network News) Reply-To: schmidt@glacier.ics.uci.edu (Doug Schmidt) Organization: University of California, Irvine - Dept of ICS Lines: 31 In-reply-to: mthome@bbn.com (Mike Thome) In article <46991@bbn.COM>, mthome@bbn (Mike Thome) writes: >Now that I've got g++ working here (thanks those who responded to my >earlier plea for help), I've got another problem... >The following code fragment (from InterViews): > class Resource { > public: > Resource () { refcount = 1; } > ~Resource () { if (--refcount > 0) { this = 0; } } > > void Reference () { ++refcount; } > int LastRef () { return refcount == 1; } > private: > unsigned refcount; > }; > >Generates the following error message: > foo.c: In method Resource::~Resource (): > foo.c:4: assignment of read-only parameter `$this' > >As far as I can tell from Stroustrup, this appears to be a perfectly >valid use of THIS in a destructer. What's going on here? Assigning to this is an anachronism. However, you can make g++ accept this via the -fthis-is-variable option. Doug -- Master Swordsman speak of humility; | schmidt@ics.uci.edu (ARPA) Philosophers speak of truth; | office: (714) 856-4034 Saints and wisemen speak of the Tao of no doubt; The moon, sun, and sea speaks for itself. -- Hiroshi Hamada