Topic: The type of the this pointer


Author: Dawn Koffman <dkoffman@cnj.digex.net>
Date: 1996/02/02
Raw View
Question 1

The ARM says:

    "The type of this in a member function of class X is X *const unless
     the member function is declared const or volatile; in those cases,
     the type of this is const X *const and volatile X *const, respectively."

9.4.2 of the 4/95 draft standard says:

    "The type of this in a member function of class X is X*.  If the member
     function is declared const, the type of this is const X*, if the member
     function is declared volatile, the type of this is volatile X*, and
     if the member function is declared const volatile, the type of this
     is const volatile X*."

Why has the type of this changed from X* const to X*, and from const X* const
to const X*?

Question 2

9.4.2 of the draft standard goes on to say:

    "In a const member function, the object for which the function is called
     is accessed through a const access path; therefore, a const member
     function shall not modify the object and its non-static data members."

This section of the draft standard doesn't say anything to indicate that
mutable data members may be modified inside const member functions.  However,
a simple example in D&E (page 287) seems to show that they may.

Where in the draft standard is there an indication that mutable data members
_may_ be modified inside const member functions?  And, assuming they may,
what mechanism allows this, given that in a const member function the object
is accessed through a const access path?
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy is
  in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]