Sat Dec 25

注意,以下聲明是不同的哦

int *matrix[10]; // array of 10 pointers

int (*matrix)[10]; // pointer to an array of 10 ints

 

因爲[]的優先級要比*的優先級高。

 

***************************************

***************************************

 

const 不能作爲函數重載的差異。

例如:

int test( int t );

int test( const int t );

 

gcc 會報 “函數重定義”。

 

但應參與const 形參的等價性僅適用於  非引用形參

對於引用參數,指針參數,const能作爲重載的差異。

 

注意: 不能給予指針本身是否爲const來實現函數重載。

void f(int *);

void f(int *const); // redeclaration

 

 

***************************************

***************************************

 

函數的局部聲明可以屏蔽其他的重載的函數聲明。

對編譯器的名稱解析有重大影響。


 

***************************************

***************************************


重載確定的三個步驟
1,確定同名的函數中那些作用域可見的函數
2,通過實參確定可行函數。(a 形參個數與實參個數,b 實參類型與形參類型)
3,尋找最佳匹配 (類型精確>隱式轉換)
1 精確匹配
2 類型提升匹配
3 標準轉換匹配
4 類類型轉換匹配

***************************************

***************************************


函數指針類型
typedef int (*pf)(int, int);
pf ff(int); //return to a pointer of function

函數類型
typedef int f(int, int);
f *ff(int); // return to a pointer of function

***************************************

***************************************

argument is different from parameter.
argument is the value (R) passed into the function.
parameter is the value (L) variable defined to accept the argument's value.

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章