Calling operator() via a Pointer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Paul Bilokon
    New Member
    • Nov 2007
    • 6

    #1

    Calling operator() via a Pointer

    Hi all,

    A very simple question, but I couldn't find a definitive answer in the literature. Functors provide you with the function call syntax:
    Code:
    foo(1, 2, 3)
    may be a call to a functor. Now, what if I have a pointer to a functor instead? Is the following syntax the recommended, or perhaps the only, way to call operator() on a functor pointer:
    Code:
    fooPtr->operator()(1, 2, 3)
    Many thanks!

    Regards,
    Paul
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    I assume you are nit using the STL since STL functions cannot have more than 2 arguments.

    That said, your code is correct. You can also:
    [code=cpp]
    (*fooptr)(1,2,3 );
    [/code]

    Comment

    • Paul Bilokon
      New Member
      • Nov 2007
      • 6

      #3
      Thanks a lot, weaknessforcats .

      No, I am not using STL; it's my own custom functor.

      I prefer your syntax, as it emphasises the function call semantics, rather than the "operator() ".

      Many thanks,
      Paul

      Comment

      Working...