Xref: utzoo comp.lang.c++:6061 gnu.g++:588 Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!utoday!comeau From: comeau@utoday.UUCP (Greg Comeau) Newsgroups: comp.lang.c++,gnu.g++ Subject: Re: function modifiers Message-ID: <1141@utoday.UUCP> Date: 10 Jan 90 16:33:33 GMT References: <14940@robin.cs.nott.ac.uk> Reply-To: comeau@.UUCP (Greg Comeau) Organization: UNIX Today!, Manhasset, NY Lines: 30 In article <14940@robin.cs.nott.ac.uk> gas@cs.nott.ac.uk (Alan Shepherd) writes: >In the code for the NIH library, there are several declarations ...: > const Object* Object::method() const; > friend const Object* Object::method() const; > >I've tried to compile this with g++-1.36.2 and discovered that friends >aren't allowed to have function modifiers in g++ i.e the terminating const. >Removing the terminating const causes lots of other related error messages >to do with const member functions calling non-const member functions etc. > >Alan Shepherd This is correct. The thing is a const member function can be used with both const data and non-const data, however a non-const member function can only be used with non-const data so removing the const means that any const object that was being manipulated by the previous const function can no longer be manipulated (where manipulated is really == modified) since it must maintain the semantics of operations performed on const data whether that data be member data or non-member data (say an external global const instance of a class). So since NIH is working code though, removing the const means that when a const MF calls a non-const MF it has no way to keep track of what the non-const function is doing. In cfront 2.0 this produces a warning though and not an error. -- Greg, Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418 Also, mag writer for UNIX Today! (SysAdm columnist), Microsoft Systems Journal (C programming), + others. Also, BIX c.language & c.plus.plus conf. moderator. Here:attmail!csanta!greg / BIX:comeau / CIS:72331, 3421 / voice:718-849-2355