爲什麼我們總是需要一個朋友函數來重載(>>)流或者(< <)out流操作符。in stream(>>)and out stream(<<)object overloading
0
A
回答
0
它不一定是朋友,除非對象包含無法以其他方式訪問的私有數據成員。
例如,如果類恰好具有所有成員的getter和setter,則可以使用這些類實現運算符。在這種情況下,它不一定是朋友。
-1
插入運算符< <重載了好友函數。重載的運算符允許我們直接使用cout語句顯示對象的內容。執行cin語句後,抽取運算符被重載,操作符被調用。有關更詳細的說明,請參閱this。
相關問題
- 1. C++ Template >> and << Overloading trouble
- 2. 如何將Map <String,List <Object>>流式傳輸到Stream <Entry <String,Object >>?
- 3. Mono <>與Spring Cloud Stream
- 4. <out T> vs <T> in Generics
- 5. 如何使用.stream()對java8中的<Map <String,Object >>進行排序?
- 6. ArrayList <Object <ArrayList <Object> >>
- 7. Stream Operator Overloading
- 8. 錯誤:read_util:read_line_to_codes/2:<stream>不存在
- 9. Java 8 stream for Map <String,Set <String>>
- 10. C#列表<Stream>處理/關閉
- 11. <machinekey> in web.config and machine.config
- 12. Escape < and > in sed/shell
- 13. if(<object> == <int>)
- 14. 轉換List <Staging <Importable>>轉換爲List <Staging <ImportableImpl >> with java 8 stream
- 15. Mock.Of <Object> VS模擬<Object>()
- 16. List <Object> listObject = new ArrayList <Object>()?
- 17. 演員表<Object> to List <Map <String,Object >>
- 18. <noscript> in <head>
- 19. 使用Java Stream API轉換類型X到Y <K, Map<V, X>>使用Java Stream API
- 20. 運營商<< and >>重載
- 21. inoremap <Tab><Esc> and <C-I><Tab>
- 22. 中心<img /> + <a /> inside table and overflow auto in IE7
- 23. DLL <object>
- 24. 的Javascript運營商<< and >>
- 25. set ArrayList <HashMap <String,Object>> value
- 26. 替換&amp;&,<lt < and > gt gt to gt在javascript中
- 27. Cast ISomeInterface <Nullable <bool>> to ISomeInterface <object>
- 28. Java Stream - 編譯時錯誤 - 類型不匹配:無法從Map <Object,Object>轉換爲Map <整數,列表<String>>
- 29. 替代品列表<object> in j2me?
- 30. 檢查List <Dictionary <string,object >>中是否存在Dictonary <string,object>?