473,387 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:st*****@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]

Mar 20 '06 #1
2 1552
FT wrote:
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"?


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
--
Please remove capital As from my address when replying by mail
Mar 20 '06 #2
FT wrote:
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."

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Mar 20 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Nitin Bhardwaj | last post by:
Hi all, It is said that C++ is a strongly typed language and thus a type-safe language (unlike C). So how does one explain the following behaviour : int main(void) { char *p = NULL; p = "A...
13
by: herrcho | last post by:
int intcmp(const void *a, const void *b) { return (*(int*)a - *(int*)b); } in the above , if i put just 'void' instead of 'const void' as a parameter, what's the difference ?
6
by: Jason | last post by:
I have a function (Inet_ntop) that returns const char * and if I try to assign that return value to a char * variable, I get the gcc error message: warning: assignment discards qualifiers from...
15
by: Chris Readle | last post by:
Hi all, Somewhat new to C and I'm getting the following error from my latest code. Here's the warning I'm getting: chris_readle_project3_assignment3.c: In function `main':...
4
by: st_ev_fe | last post by:
Hi people, I've been doing C for about 7 years now. But I'm new to C++. I've decided that C++'s operator overloading could be very handy. I'm writing something much like auto_ptr, except for...
1
by: lovecreatesbeauty | last post by:
There is a warning/(error? I remember it is an error for line 10 on some compilers before. At least on g++, it is an error.) for line 10. I first read a similar example from `Expert C Programming...
33
by: Ney André de Mello Zunino | last post by:
Hello. I have written a simple reference-counting smart pointer class template called RefCountPtr<T>. It works in conjunction with another class, ReferenceCountable, which is responsible for the...
8
by: minseokoh | last post by:
Hi, Could someone explain why "const" is located after the function name and what it means? inline unsigned char *access(int off) const { if (off < 0) abort(); return (&bits_); }
3
by: somenath | last post by:
Hi All, I got some questions regarding the type of expression . For example 1)char *const *(*ptr)(); Here the type of ptr is it is constant pointer to a function which accept unspecified...
16
by: PeterAPIIT | last post by:
Hello all C++ expert programmer, i have wrote partial general allocator for my container. After reading standard C++ library and code guru article, i have several questions. 1. Why...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.