473,320 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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!

Regards,
Paul
Nov 15 '07 #1
2 5448
weaknessforcats
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);
  2.  
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,
Paul
Nov 16 '07 #3

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

Similar topics

5
by: Praveen Srinivasan | last post by:
Hi all, Are there any important issues that one should be aware of when calling C++ functions from C? In particular, I'm passing a function pointer to a C routine in a library, and in that...
2
by: John J | last post by:
I have written the following overload of operator << as a display function. In the code I unsuccessfully try and call a function within another class(<< "Race : " << r->Show () << endl). The Show...
3
by: matt p | last post by:
example: FunClass myfun; FunClass *lotsofunptr=&myfun; myfun; //calls the overloaded operator; lotsofunptr->;//error help is much apreciated
5
by: Kelvin Moss | last post by:
Hi all, The prototype for atexit is 'int atexit(void (*function)(void))'; If I have a function foo defined as void foo(void) { } then what is the correct way to register the handler -
4
by: Michael | last post by:
Hello, I want to use an object (LowCut) within another object (SampleRateConverter) like it is written as follows: class SampleRateConverter { public: SampleRateConverter( int...
18
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
5
by: raylopez99 | last post by:
I need an example of a managed overloaded assignment operator for a reference class, so I can equate two classes A1 and A2, say called ARefClass, in this manner: A1=A2;. For some strange reason...
3
by: Howard Swope | last post by:
Greetings: C++ CLR .Net 2 I have a ref class that I have created that wraps an unmanaged pointer. It acts like a smart pointer for reference counted objects for a particular library I am...
61
by: Ron Ford | last post by:
K&R has three different versions of qsort, and the ultimate one is supposed to be like the one in the std library. I'm trying to implement the first, which is in §4.10. I think I'm pretty close...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.