By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,128 Members | 1,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,128 IT Pros & Developers. It's quick & easy.

why some operators cannot be overloaded

P: n/a
Hi,
Can anybody explain , why some operators(::, ., .*, sizeof,?:) cannot
be
overloaded in C++?

Thanks

Jul 26 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
> Hi,
Can anybody explain , why some operators(::, ., .*, sizeof,?:) cannot
be
overloaded in C++?

Thanks


http://www.research.att.com/~bs/bs_f...l#overload-dot
Jul 26 '05 #2

P: n/a
Ian
Bangalore wrote:
Hi,
Can anybody explain , why some operators(::, ., .*, sizeof,?:) cannot
be
overloaded in C++?

Because it makes no sense to do so.

Ian
Jul 26 '05 #3

P: n/a
Besides the sense can there be any other reasons??

Suresh

Jul 27 '05 #4

P: n/a
suresh wrote:
Ian wrote:
Because it makes no sense to do so.

Ian

well thats not entirely true. There are very good reasons to overload either
operator. and operator.* which is why allowing it is seriously considered
for the next version of C++

see: http://www.open-std.org/JTC1/SC22/WG...2004/n1671.pdf

It is usful to implement smart references or other forwarding handles.

Besides the sense can there be any other reasons??

Suresh


Well it is certainly a good policy not to allow things which make no sence.

The problem with all operator overloads is that it might lead to confusion,
if the overloaded operators work differently from the "normal" version.
In the case of an overloaded operator. There is for example no obvious way
to call member functions of the class which overloads the operator.

If you are interested in why c++ is as it is, you probably want to read
Design & Evolution of C++ by Bjarne Stroustrup.
HTH

Fabio
Jul 27 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.