470,863 Members | 1,132 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,863 developers. It's quick & easy.

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:
Expand|Select|Wrap|Line Numbers
  1. 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:
Expand|Select|Wrap|Line Numbers
  1. fooPtr->operator()(1, 2, 3)
Many thanks!

Nov 15 '07 #1
2 5150
9,208 Expert Mod 8TB
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:
Expand|Select|Wrap|Line Numbers
  1. (*fooptr)(1,2,3);
Nov 15 '07 #2
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,
Nov 16 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Praveen Srinivasan | last post: by
2 posts views Thread by John J | last post: by
5 posts views Thread by Kelvin Moss | last post: by
61 posts views Thread by Ron Ford | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.