[comp.lang.c] const methods

Michael_Hoennig@hh.maus.de (Michael Hoennig) (06/23/91)

Hi Marina,

MG>        virtual int f() const;
MG>Does anybody know the meaning of this const postfix ??

this method will not change the object to which this is pointing.
If you will use const parameters of a class, you can only access
these const-methodes:

class X
{
    int n;
public:
    ...
    void theConst() const;
    void theOther();
    ...
};

void foo( const X aX )
{
    X.theConst(); // allowed
    X.theOther(); // not allowed, type mismatch error or warning
}

Adios

--
Michael Hoennig -- Dobbelersweg 45 -- D-2000 Hamburg 26 -- ++49 40 219 24 58
office: mi1@starlab.UUCP -- ++49 40 23 08 56 (StarDivision Hamburg)