Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!bloom-picayune.mit.edu!bloom-beacon!eru!hagbard!sunic!ericom!eua.ericsson.se!euamts From: euamts@eua.ericsson.se (Mats Henricson) Newsgroups: comp.lang.c++ Subject: Re: Help needed in c++ Message-ID: <1991Jun19.132158.8495@eua.ericsson.se> Date: 19 Jun 91 13:21:58 GMT References: <3257@odin.cs.hw.ac.uk> Sender: news@eua.ericsson.se Organization: Ellemtel Telecom Systems Labs, Stockholm, Sweden Lines: 34 Nntp-Posting-Host: euas20c01.eua.ericsson.se marina@cs.hw.ac.uk (Marina Georgiadou) writes: >I'm currently working in Borland C++, and I have encountered >the following construct in one of Borland's examples : >class A{ >// ... >public : > virtual int f() const; >//... >}; >Does anybody know the meaning of this const postfix ?? Well, I suppose you have got 600 replys allready, but who knows: The const postfix means that the function f() may not change any of the data members of the class A. This is a very neat feature since you know that this function is safe for the data in the object of type A. It has however yet another meaning: if you have a constant object of type A: const A a; Now you can only use the member functions of A that are declared const. This is rather natural; since a is declared const it cannot be changed, and hence only safe functions that does not change the inner state of a should be possible to call. If you were using g++, i.e. GNU:s version of C++, this const postfix would have yet another meaning, since the GNU compiler does not allow const functions to change ANYTHING, i.e. not even global constants. You are using Borland C++ and it should not put this restraint on const declared functions. So just forget you heard about it ;-) Mats Henricson, Sweden