我定义了一个指向函数类型的指针:
typedef uint32_t (*funct_t)(bool);
我声明了一个使用相同接口的函数:
uint32_t a_funct(bool);
我需要使用指向函数类型的指针。我怎么能这样做?
答案 0 :(得分:3)
如果你这样定义typedef:
typedef uint32_t (funct_t)(bool); // note the missing * before the type name
您可以声明这样的函数:
funct_t a_funct;
请注意,在定义函数时,仍需要拼出参数。
uint32_t a_funct(bool x)
{
...
}
答案 1 :(得分:2)
我定义了一个函数类型:
typedef uint32_t (*funct_t)(bool);
不,你没有声明一个功能。您声明了指向函数类型的指针。
声明你可以编写的函数类型
typedef uint32_t funct_t(bool);
然后您可以使用该类型来声明函数a_funct
funct_t a_funct;
考虑到您不能使用函数类型的typedef来定义函数。