why some operators cannot be overloaded

Discussion in 'C++' started by Bangalore, Jul 26, 2005.

  1. Bangalore

    Bangalore Guest

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

    Thanks
     
    Bangalore, Jul 26, 2005
    #1
    1. Advertising

  2. Bangalore

    benben Guest

    benben, Jul 26, 2005
    #2
    1. Advertising

  3. Bangalore

    Ian Guest

    Bangalore wrote:
    > Hi,
    > Can anybody explain , why some operators:):, ., .*, sizeof,?:) cannot
    > be
    > overloaded in C++?
    >

    Because it makes no sense to do so.

    Ian
     
    Ian, Jul 26, 2005
    #3
  4. Bangalore

    suresh Guest

    Besides the sense can there be any other reasons??

    Suresh
     
    suresh, Jul 27, 2005
    #4
  5. 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/WG21/docs/papers/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
     
    Fabio Fracassi, Jul 27, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. -Steve-
    Replies:
    2
    Views:
    387
    - Steve -
    Jul 28, 2003
  2. John Harrison
    Replies:
    5
    Views:
    347
    - Steve -
    Jul 29, 2003
  3. Brad Eck
    Replies:
    20
    Views:
    46,316
    Alex Vinokur
    Oct 30, 2004
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,271
    Smokey Grindel
    Dec 2, 2006
  5. Replies:
    14
    Views:
    1,339
    Girish Shetty
    Aug 12, 2005
Loading...

Share This Page