Overloading typeid operator

Discussion in 'C++' started by Sarath, Feb 27, 2008.

  1. Sarath

    Sarath Guest

    Hello All

    Is it possible to overload typeid operator? In my understanding it's
    not possible Could you please provide more information on same?

    Regards,
    Sarath
    Sarath, Feb 27, 2008
    #1
    1. Advertising

  2. Sarath

    Micah Cowan Guest

    Sarath wrote:
    > Hello All
    >
    > Is it possible to overload typeid operator? In my understanding it's
    > not possible Could you please provide more information on same?


    It is not possible. Neither is overloading sizeof, or any of ., .*, ::
    or ?:.

    All of these operators have important and specific meanings, and would
    be severely undermined if users were able to change their meanings.

    For typeid, for instance, the whole point is to uniquely identify a
    type. If you're trying to make a user-defined type "look" like another
    type, you're better off taking advantage of polymorphism and/or
    type-conversion (a lá opertor bool(), etc) semantics; typeid is, as it
    ought to be, sacrosanct.

    --
    Micah J. Cowan
    Programmer, musician, typesetting enthusiast, gamer...
    http://micah.cowan.name/
    Micah Cowan, Feb 27, 2008
    #2
    1. Advertising

  3. Sarath

    Sarath Guest

    On Feb 27, 1:49 pm, Micah Cowan <> wrote:
    > Sarath wrote:
    > > Hello All

    >
    > > Is it possible to overload typeid operator? In my understanding it's
    > > not possible Could you please provide more information on same?

    >
    > It is not possible. Neither is overloading sizeof, or any of ., .*, ::
    > or ?:.
    >
    > All of these operators have important and specific meanings, and would
    > be severely undermined if users were able to change their meanings.
    >
    > For typeid, for instance, the whole point is to uniquely identify a
    > type. If you're trying to make a user-defined type "look" like another
    > type, you're better off taking advantage of polymorphism and/or
    > type-conversion (a lá opertor bool(), etc) semantics; typeid is, as it
    > ought to be, sacrosanct.
    >
    > --
    > Micah J. Cowan
    > Programmer, musician, typesetting enthusiast, gamer...http://micah.cowan.name/


    Thanks a lot for the information. It's clear now.

    Regards
    Sarath.
    Sarath, Feb 27, 2008
    #3
    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. John Smith
    Replies:
    2
    Views:
    410
    Ivan Vecerina
    Oct 6, 2004
  2. Marco Jez

    typeid operator

    Marco Jez, Oct 27, 2004, in forum: C++
    Replies:
    20
    Views:
    1,938
    Pete Becker
    Oct 31, 2004
  3. Replies:
    11
    Views:
    715
    James Kanze
    May 16, 2007
  4. hurcan solter
    Replies:
    3
    Views:
    712
    Cholo Lennon
    Aug 29, 2007
  5. Replies:
    11
    Views:
    543
Loading...

Share This Page