4
A
回答
1
的->*
和.*
運營商是通過指針訪問類成員,請參見以下鏈接的例子:
http://c-for-crogrammers.org.ua/ch22lev1sec6.html
您可能會發現this SO answer也是有用的。
1
operator->*
是針對成員的指針。
struct foo{
void bar(){}
};
int main(){
typedef void (foo:*foo_memptr)();
foo_memptr pfunc = &foo::bar;
foo f;
foo* pf = &f;
(f.*pfunc)(); // on object or reference
(pf->*pfunc)(); // on pointer to object
}
重載它通常只爲智能指針是有用的,甚至因爲它是非常複雜和相同的功能可以通過((*pf).*pfunc)()
實現他們不這樣做。斯科特邁爾斯甚至寫道a PDF on how to do it!
相關問題
- 1. >>運營商超過/運營商的優勢
- 2. PHP - >運營商
- 3. Angular2 =>運營商
- 4. javascript「=>」運營商
- 5. 曖昧使用運營商的 '>'
- 6. 運營商不能使用?
- 7. 轉換運營商和運營商>>
- 8. 的JavaScript =>運營商
- 9. 使用運營商
- 10. 使用「?」運營商
- 11. ==運營商的成本vs < or >運營商
- 12. 超載運營商 - >
- 13. 運營商'。' VS ' - >' 在C++
- 14. 運營商的模糊過載>>
- 15. istream&運營商的問題>>
- 16. 的Javascript運營商<< and >>
- 17. QVector <T>運營商=和運營商[]
- 18. Scala |運營商「=>」等這類運營商
- 19. 使用新的運營商
- 20. 運營商的情況下運營商
- 21. 的JavaScript +運營商VS - 運營商
- 22. 運營商<< and >>重載
- 23. cygwin不承認>>運營商? C++
- 24. C++流和運營商>>優先
- 25. 不匹配運營商>>問題
- 26. Bigint運營商>>超載
- 27. 爲「運營商>>」曖昧超載
- 28. 冷聚變創建使用<strong>新</strong>運營商的「新」運營商
- 29. 使用蒙戈$切片運營商與其他運營商
- 30. C++使用,而不是運營商運營商INT()+
參見http://stackoverflow.com/questions/2696864/are-free-operator-overloads-evil。我不認爲這是上述的重複,但也不是一個很好的問題。 – Potatoswatter 2012-01-03 20:11:10
我要回答,但這裏是jist - 'operator - > *'定義了一個二元運算符,就像'operator +','operator *'等一樣。它比所有其他二元運算符具有更高的優先級,所以它是有用的在形成成員訪問時,但低於'operator []'。它被廣泛認爲是模糊的,可能會混淆用戶。 – Potatoswatter 2012-01-03 20:18:47