2011-12-18 17 views
2

我正在查看v8頭文件,並再次出現問題。什麼是v8中的AccessorGetter和AccessorSetter typedefs?

https://github.com/joyent/node/blob/master/deps/v8/include/v8.h#L1408-1414

typedef Handle<Value> (*AccessorGetter)(Local<String> property, 
            const AccessorInfo& info); 


typedef void (*AccessorSetter)(Local<String> property, 
          Local<Value> value, 
          const AccessorInfo& info); 

我不知道這個的typedef用?

+0

這兩個'typedef'定義了_pointer-to-a-function_:'AccessorGetter'和'AccessorSetter'類型。 – lapk 2011-12-18 03:54:19

回答

0

這兩個類型定義爲指向與給定簽名匹配的函數的指針創建簡單名稱。

typedef Handle<Value> (*AccessorGetter) 
    (Local<String> property, 
    const AccessorInfo& info); 

這定義了一個新類型AccessorGetter可用於創建包含一個函數的地址與簽名

Handle<Value> SampleAccessorGetter 
    (Local<String> property, 
    const AccessorInfo& info) 
{ 
    // ... 
} 

變量,它可以在代碼中使用,例如:

int main() 
{ 
    // two variables that contain the address of `SampleAccessorGetter`. 
    AccessorGetter f = &SampleAccessorGetter; 
    AccessorGetter g = &SampleAccessorGetter; 

    // these variables can be used to call the pointee function: 
    f(...); 
    g(...); 
} 
+0

第一個'()'是表達式,第二個'()'是函數,對吧? – 2011-12-18 12:10:42

0

AccessorGetterAccessorSetter是函數指針類型,它們取右邊的參數並在左邊有返回類型。

0

那些正在定義函數指針類型。

第一聲明類型AccessorGetter是一個指針,它指向採用兩個參數,一個Local<String>const AccessorInfo&的功能,並返回一個Handle<Value>

第二聲明類型AccessorSetter是一個指針取三個值(Local<String>, Local<Value>, and const AccessorInfo&)以及返回什麼(void)的功能。

0

這是一個函數指針: Handle(* AccessorGetter)(Local property,const AccessorInfo & info);

這是這種函數指針的typedef: typedef Handle(* AccessorGetter)(Local property,const AccessorInfo & info);

相關問題