sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
Bangalore's Avatar

why some operators cannot be overloaded


Question posted by: Bangalore (Guest) on July 26th, 2005 07:55 AM
Hi,
Can anybody explain , why some operators(::, ., .*, sizeof,?:) cannot
be
overloaded in C++?

Thanks

4 Answers Posted
benben's Avatar
Guest - n/a Posts
#2: Re: why some operators cannot be overloaded

> Hi,[color=blue]
> Can anybody explain , why some operators(::, ., .*, sizeof,?:) cannot
> be
> overloaded in C++?
>
> Thanks
>[/color]

http://www.research.att.com/~bs/bs_...ml#overload-dot


Ian's Avatar
Guest - n/a Posts
#3: Re: why some operators cannot be overloaded

Bangalore wrote:[color=blue]
> Hi,
> Can anybody explain , why some operators(::, ., .*, sizeof,?:) cannot
> be
> overloaded in C++?
>[/color]
Because it makes no sense to do so.

Ian
suresh's Avatar
Guest - n/a Posts
#4: Re: why some operators cannot be overloaded

Besides the sense can there be any other reasons??

Suresh

Fabio Fracassi's Avatar
Fabio Fracassi July 27th, 2005 04:45 PM
Guest - n/a Posts
#5: Re: why some operators cannot be overloaded

suresh wrote:[color=blue]
> Ian wrote:
>[color=green]
> > Because it makes no sense to do so.
> >
> > Ian[/color][/color]

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/W.../2004/n1671.pdf

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

[color=blue]
> Besides the sense can there be any other reasons??
>
> Suresh[/color]

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
 
Not the answer you were looking for? Post your question . . .
196,816 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 196,816 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors