🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3238

Re: The type of the this pointer

#3238
From: 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
]
Technical Details
Message-ID: <4f0vd7$ma6@engnews1.Eng.Sun.COM>
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
References: <199602022342.SAA23370@cnj.digex.net>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
From: clamage@Eng.sun.com (Steve Clamage)
Newsgroups: comp.std.c++
Subject: Re: The type of the this pointer
Date: 4 Feb 1996 00:50:42 GMT
Organization: Sun Microsystems Inc., Mountain View, CA
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <4f0vd7$ma6@engnews1.Eng.Sun.COM>
References: <199602022342.SAA23370@cnj.digex.net>
NNTP-Posting-Host: taumet.eng.sun.com
Content-Type: text
X-Nntp-Posting-Host: taumet.eng.sun.com
X-Newsreader: NN version 6.5.0 #21 (NOV)
Content-Length: 1730
Originator: clamage@taumet