why Cannot Overload the operators in C++

C

chenthil

Hi All,

Why we can't overload . , .*, :: , ?: and sizeof () operators in C++.
Any one please help me.

Thanks and Regards
K.Chenthil.
 
J

James Kanze

Because of §1.5/3 of the standard.
You cannot overload preprocessing symbols # and ## either
(from n2914).
Concerning the reason why those operators weren't included
see:http://www.research.att.com/~bs/bs_faq2.html#overload-dot

Which is a very good explination, honest and open. (I mention
this because I've read other statements which pretend that the
current situation is the only one which could possibly make any
sense.) There are some operators, like ::, # and ##, where
overloading is completely imposible, because they are strictly
compile time. There is a very strong argument against sizeof
and unary &, since they are defined for all types, and have
results which can be used in constant expressions (evaluated at
"compile" time)---note that despite this, you can overload unary
&. For the others (., .*, and ?:), there's more room for
discussion---one could also present a good argument that we
shouldn't be able to overload && and || (since the overloaded
forms can't short circuit and don't introduce the same ordering
constraints).

From a pratical point of view, I sometimes miss operator.() (for
smart references), and in practice, never overload && and ||
(and about the only time I'll overload unary& is to make it
private, so that the address of the object can't be taken). On
the whole, given that the current situation is unchanged from
the introduction of operator overloading, and the almost total
lack of real experience with operator overloading when the
choices were made, I'd say that they worked out pretty well.
 

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

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top