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. Overloading function operator ()

Overloading function operator ()

Scheduled Pinned Locked Moved C / C++ / MFC
question
14 Posts 9 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.
  • P Prakash Nadar

    I agree with you, no need to overload curly brackets.


    Still Alive!!! Thank you God.

    I Offline
    I Offline
    Ian Darling
    wrote on last edited by
    #5

    Mr.Prakash wrote: I agree with you, no need to overload curly brackets Two words: Function Objects ;P :-)


    Ian Darling "The trouble with the world is that the stupid are cocksure and the intelligent are full of doubt." - Bertrand Russell

    P 1 Reply Last reply
    0
    • B BIG_MG

      Can we overload the function operator () - Curly brackets ? If yes then what would be the syntax for this.

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #6

      If you mean {} then no, because they are not operators. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ Laugh it up, fuzzball.

      1 Reply Last reply
      0
      • I Ian Darling

        Mr.Prakash wrote: I agree with you, no need to overload curly brackets Two words: Function Objects ;P :-)


        Ian Darling "The trouble with the world is that the stupid are cocksure and the intelligent are full of doubt." - Bertrand Russell

        P Offline
        P Offline
        Prakash Nadar
        wrote on last edited by
        #7

        humm??? I lookedup in MSDN and it should be links for JScript.. As far as my knowldge Brase brackets are not operators so you cant overload it. brase brackets is used by the compiler for scope management of the identifiers.


        Still Alive!!! Thank you God.

        D I 2 Replies Last reply
        0
        • P Prakash Nadar

          humm??? I lookedup in MSDN and it should be links for JScript.. As far as my knowldge Brase brackets are not operators so you cant overload it. brase brackets is used by the compiler for scope management of the identifiers.


          Still Alive!!! Thank you God.

          D Offline
          D Offline
          Daniel Turini
          wrote on last edited by
          #8

          STL uses it all the time: they are called 'functors'. Search MSDN or Google for functors and you'll understand what I mean. Perl combines all the worst aspects of C and Lisp: a billion different sublanguages in one monolithic executable. It combines the power of C with the readability of PostScript. -- Jamie Zawinski

          1 Reply Last reply
          0
          • P Prakash Nadar

            humm??? I lookedup in MSDN and it should be links for JScript.. As far as my knowldge Brase brackets are not operators so you cant overload it. brase brackets is used by the compiler for scope management of the identifiers.


            Still Alive!!! Thank you God.

            I Offline
            I Offline
            Ian Darling
            wrote on last edited by
            #9

            Right: You can overload normal parenthesis, being (), which is what I think the original poster really meant. You can't overload curly braces {}, because it's meaningless (although I could see some possible uses for lambda constructs, perhaps.)


            Ian Darling "The trouble with the world is that the stupid are cocksure and the intelligent are full of doubt." - Bertrand Russell

            J 1 Reply Last reply
            0
            • I Ian Darling

              Right: You can overload normal parenthesis, being (), which is what I think the original poster really meant. You can't overload curly braces {}, because it's meaningless (although I could see some possible uses for lambda constructs, perhaps.)


              Ian Darling "The trouble with the world is that the stupid are cocksure and the intelligent are full of doubt." - Bertrand Russell

              J Offline
              J Offline
              Jorgen Sigvardsson
              wrote on last edited by
              #10

              Ian Darling wrote: You can't overload curly braces {}, because it's meaningless (although I could see some possible uses for lambda constructs, perhaps.) Or thunks (for the Smalltalk 80 perverted people :rolleyes:) -- So let's just walk from place to place, as long as we don't talk face to face.

              B 1 Reply Last reply
              0
              • J Jorgen Sigvardsson

                Ian Darling wrote: You can't overload curly braces {}, because it's meaningless (although I could see some possible uses for lambda constructs, perhaps.) Or thunks (for the Smalltalk 80 perverted people :rolleyes:) -- So let's just walk from place to place, as long as we don't talk face to face.

                B Offline
                B Offline
                BIG_MG
                wrote on last edited by
                #11

                No I mean for parenthesis (). This has been asked to me during an interview. Can we overload function operator () ? If yes then how and in what scenario this would be required.

                R J 2 Replies Last reply
                0
                • B BIG_MG

                  No I mean for parenthesis (). This has been asked to me during an interview. Can we overload function operator () ? If yes then how and in what scenario this would be required.

                  R Offline
                  R Offline
                  Robert A T Kaldy
                  wrote on last edited by
                  #12

                  class multiplier
                  {
                  public:
                  int operator()(int i) { return i * 3; }
                  };

                  multiplier mul;
                  cout << mul(10); // should return 30

                  Robert-Antonio "Life is very hard, when you apply E-R model to it."

                  B 1 Reply Last reply
                  0
                  • B BIG_MG

                    No I mean for parenthesis (). This has been asked to me during an interview. Can we overload function operator () ? If yes then how and in what scenario this would be required.

                    J Offline
                    J Offline
                    Jorgen Sigvardsson
                    wrote on last edited by
                    #13

                    With all due respect, are you blind? Did you not see the first response to your query? -- So let's just walk from place to place, as long as we don't talk face to face.

                    1 Reply Last reply
                    0
                    • R Robert A T Kaldy

                      class multiplier
                      {
                      public:
                      int operator()(int i) { return i * 3; }
                      };

                      multiplier mul;
                      cout << mul(10); // should return 30

                      Robert-Antonio "Life is very hard, when you apply E-R model to it."

                      B Offline
                      B Offline
                      BIG_MG
                      wrote on last edited by
                      #14

                      Thanks Robert.

                      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