2014-07-22 88 views

回答

1

它将func定义为接受3个整数并返回整数的函数的类型。

当您将函数作为回调函数传递或将函数地址放入数组或类似的东西时,这会很有帮助。

0

它定义了一个类型func,它是一个函数的指针,返回一个int并取参数3 int

使用此的一个例子是:

typedef int (*func) (int, int, int); 

int foo(int a, int b, int c) { 
    return a + b * c; 
} 

... 

// Declare a variable of type func and make it point to foo. 
// Note that the "address of" operator (&) can be omitted when taking the 
// address of a function. 
func f = foo; 

// This will call foo with the arguments 2, 3, 4 
f(2, 3, 4); 

一个更现实的情况可能有一堆具有相同的返回类型的功能和采取的参数相同类型/号码,而且要根据某些变量的值调用不同的函数。您可以将函数指针放在数组中并使用索引来调用相应的函数,而不是拥有大量if-声明或较大的switch/case

0

这是typedef的名称。它的内容:func is a pointer to a function that takes three ints and returns an int.

你可以看到更多关于这link