简体   繁体   English

C ++如何解释函数参数long(* pPointer)(OtherClass * const,long)?

[英]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 ? 类型为long的指针,还是指向OtherClass的实例的OtherClass What is the meaning of ,long in the end? 是什么意思,long在结束了吗?

In the doxygen documentation this syntax resolves to: 在doxygen文档中,此语法解析为:

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. 它是指向一个函数的指针,该函数接受其他类型的参数和long并返回long。 The name of the function pointer is pPointer. 函数指针的名称是pPointer。

This is a pointer to a function named pPointer (the naming is debatable here). 这是指向名为pPointer的函数的指针(此处的名称值得商pPointer )。 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);
}  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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