為什麼 function 可以 deref 好幾次結果仍相等
簡單解釋來說是存在著隱式轉換把 point 轉換到 function,這樣不管你解參考幾次都會自己轉回來,而參考只能參考一次。
參考
- c++ 11 說明頁有提到隱式轉換 (忘了昨天在哪裡看到)
[6.3.2.1-4]
4 Afunction designator is an expression that has function type. Except when it is the operand of the sizeof operator, the _Alignof operator,65) or the unary & operator, a function designator with type ‘‘function returning type’’ is converted to an expression that has type ‘‘pointer to function returning type’’.
[6.5.3.2-1]
The operand of the unary & operator shall be either a function designator, the result of a [] or unary * operator, or an lvalue that designates an object that is not a bit-field and is not declared with the register storage-class specifier.
[6.5.3.2-4]
The unary * operator denotes indirection. If the operand points to a function, the result is a function designator; if it points to an object, the result is an lvalue designating the object.
If the operand has type ‘‘pointer to type’’, the result has type ‘‘type’’. If an invalid value has been assigned to the pointer, the behavior of the unary * operator is undefined.102) Forward references: storage-class specifiers (6.7.1), structure and union specifiers (6.7.2.1).
沒有留言:
張貼留言