🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Dawn Koffman Sat, 03 Feb 1996 03:31
The type of the this pointer
#3214
Author: Dawn Koffman
Date: Sat, 03 Feb 1996 03:31
39 lines
2341 bytes
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. ]
Re: The type of the this pointer
#3238
Author: Steve Clamage
Date: Sun, 04 Feb 1996 00:50
49 lines
2592 bytes
Dawn Koffman <dkoffman@cnj.digex.net> writes:

>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*?


The draft also says "this" is a non-lvalue expression. Since "this"
isn't an lvalue, const-ness is irrelevant. You can't assign to it or
take its address, so const would have no effect for any operation you
could perform. That is, const has a meaning only for lvalues.


>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.

The section on "mutable" (7.1.1) says it nullifies a const specifier
on the containing object and that you may assign to the data member.
It would be nice if the section on "this" mentioned "mutable".
--
Steve Clamage, stephen.clamage@eng.sun.com

[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy is
  summarized in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads