-1

我一直想问这个问题一段时间了。这些函数是怎么回事?为什么括号里是名字?

void        (*think)(gentity_t *self);
void        (*reached)(gentity_t *self);    // movers call this when hitting endpoint
void        (*blocked)(gentity_t *self, gentity_t *other);
void        (*touch)(gentity_t *self, gentity_t *other, trace_t *trace);
4

3 回答 3

3

在您的示例中,函数名中的括号表示指向函数地址的变量。如果你不使用括号

void * think(gentity_t *self);// equal (void *) think(gentity_t *self); 

意思是定义一个函数,名字:think,返回:void *,参数:gentity_t *self;这些是指向函数的变量。

于 2017-08-18T01:04:38.007 回答
2

这些声明是函数指针,它指向一个函数并且可以随时更改。

我建议您对 C 中的函数指针进行一些研究,因为它们非常有用。

如果您知道 C++,std::function那么这些实际上就是它们的旧 C 版本。

于 2017-08-18T01:03:48.377 回答
1

这些是函数指针,而不是函数名。因此它们可以指向任何具有相同类型和属性的函数。

于 2017-08-18T01:06:08.657 回答