Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. specifications of operator-overload

specifications of operator-overload

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Cold_Fearing_Bird
    wrote on last edited by
    #1

    How could I find spefications of C++ operators overload, such as how many arguments should operator+() take, what should be the first operator of operator new(), operator int() qualifies only if it's a member function. I have <>, it lists a few of them.But it doesn't satisfy my needs.could someone help me?

    C S 2 Replies Last reply
    0
    • C Cold_Fearing_Bird

      How could I find spefications of C++ operators overload, such as how many arguments should operator+() take, what should be the first operator of operator new(), operator int() qualifies only if it's a member function. I have <>, it lists a few of them.But it doesn't satisfy my needs.could someone help me?

      C Offline
      C Offline
      Code o mat
      wrote on last edited by
      #2

      Does this[^] help?

      > The problem with computers is that they do what you tell them to do and not what you want them to do. < > If it doesn't matter, it's antimatter.<

      1 Reply Last reply
      0
      • C Cold_Fearing_Bird

        How could I find spefications of C++ operators overload, such as how many arguments should operator+() take, what should be the first operator of operator new(), operator int() qualifies only if it's a member function. I have <>, it lists a few of them.But it doesn't satisfy my needs.could someone help me?

        S Offline
        S Offline
        Stefan_Lang
        wrote on last edited by
        #3

        Without googling for possibly more concise information, I do recall one thing about operator overloads: They must fit the signature of the standard operation; not with respect to type, which may be different, but with respect to number of arguments. Some operators have more strict requirements, e. g. assignmen operators should always return a value of type 'reference to the type that is being assigned to', but AFAIK these are not enorced by the compiler. It is still strongly recommended because otherwise youmight get unexpected behaviour when using these types with template libraries such as the STL. You could take a look at the interface of std::complex for a comprehensive list of overloaded operators and their signatures: complex operators P.S.: operator int() and the like, i. e. the casting operators, have their own special syntax: a) they may not have a return type (which would be redundant anyway), and b) they don't take an argument, because - as you noted - they only work as member functions. You should however consider to specify them as explicit, to prevent an accidental inappropriate use through automatic type conversion by the compiler.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups