"Charles Keepax" <s9903977@sms.e d.ac.uk> wrote...[color=blue]
> Just a little quick question what is the effect of putting a const after
> a member function definition.[/color]
It makes the function 'const'. Inside it 'this' designates
a constant object. Functions can be overloaded based on that.
For a non-const object non-const function is preferred, for
a const object only a const function will be called.
"Charles Keepax" <s9903977@sms.e d.ac.uk> wrote in message
news:bf0vem$eqm $1@scotsman.ed. ac.uk...[color=blue]
> Just a little quick question what is the effect of putting a const after
> a member function definition.
>
> Charles
>[/color]
Its a guarantee that the member function will not alter the object it is
called on. It means that the member function can be called on a const object
or via a const reference or const pointer.
"Charles Keepax" <s9903977@sms.e d.ac.uk> wrote in message
news:bf0vem$eqm $1@scotsman.ed. ac.uk...[color=blue]
> Just a little quick question what is the effect of putting a const after
> a member function definition.
>[/color]
Little quick answer :-)
The function does not modify the state of the object/class..
There are two camps on what that implies -
bitwise constness or abstract state constness.
Bitwise constness implies that no member variable gets modified.
For abstract constness consider a class
class A{
public :
void copy () ; // changes what p points to, not p..hence not const
private:
char *p;
};
Even if there is bitwise constness ( p unchanged) but if the contents of
what p points to get changed then
it is not abstract state constness.
Comment