2014-07-22 46 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