Why the type of /this/ pointer not be X* const

F

FT

Hi all:
In the standuard 9.3.2, it says:
The type of /this/ in a member function of a 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*.

IMO, the /this/ pointer can not be used as a l-value, so its type
should be X* const
instead of X*.(accordingly, const X* const instead of const X*,etc...)

Why the standuard "omit" that "const"?

(It's my first time to post on USENET. Hope me have not done any stupid
thing.)

Thanks,

FT
 
V

Victor Bazarov

FT said:
In the standuard 9.3.2, it says:

IMO, the /this/ pointer can not be used as a l-value, so its type
should be X* const
instead of X*.(accordingly, const X* const instead of const
X*,etc...)

Why the standuard "omit" that "const"?

The beginning of the paragraph you quoted states that 'this' is
a non-lvalue expression. After defining 'this' as non-lvalue, there
is no need to claim that it's "const".

V
 
P

Phlip

FT said:
IMO, the /this/ pointer can not be used as a l-value, so its type
should be X* const
instead of X*.(accordingly, const X* const instead of const X*,etc...)

Why the standuard "omit" that "const"?

'this' was invented before references. Consider 'this' as "not a pointer,
but a thing you write -> or * on".

'this' is as close to a reference as makes no difference.

You are correct the language of that Standard snip is incorrect. Yet because
'this' is not a pointer, the authors don't need to be accurate. Other
language doubtless covers "you cannot change 'this', take its address, etc."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top