简体   繁体   中英

C++ How should I interpret a function argument long(*pPointer)(OtherClass *const, long)?

I can't make any sense of this syntax. What should be passed to the function? A pointer of type long, or a pointer to an instance of OtherClass ? What is the meaning of ,long in the end?

In the doxygen documentation this syntax resolves to:

long(*)(OtherClass *const, long)    pPointer,

I've tried to search for examples of this syntax, but it is difficult to search for braces and asterisks.

It is a pointer to a function that takes an argument of othertype and long and returns a long. The name of the function pointer is pPointer.

This is a pointer to a function named pPointer (the naming is debatable here). Imagine this function somewhere in your code base:

long someFunction(OtherClass *const param1, long param2);

It can be passed to as the type in your question title as

passFct(someFunction);

where the receiving function might look like

void passFct(long (*pPointer) (OtherClass *const, long))
{
    /* ... */

    /* Actually call the function to with pPointer points: */
    pPointer(&otherClassInstance, 10l);
}  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM