看到一篇文章 https://www.fluentcpp.com/2018/07/13/the-incredible-const-reference-that-isnt- const/ 我覺得蠻有趣的 其中一段提到 The get() method returns a const T&, with T coming from template T. In our sec ond case, T is int&, so const T& is const (int&) & 這邊。const (int&) & 為什麼他可以直接看出這const 是修飾reference (int&) & const 然後就是這邊感覺多了一個& 也許他這段有解釋 So being氲onst氽oesn’t say much for a reference, since they always乸re氲onst, since they cannot rebind. This implies that氲onst (int&)湶s effectively the s ame type as湶nt&. 但實在看不是很懂 這邊能不能套用forwarding reference的規則 int& & collapse成 int&, 所以變成 int & const ,我不確定,而且覺得不能這樣想 而且正常試圖寫 https://ideone.com/95tBGJ 無法寫得出這個語意. 請問各位有什麼規則需要釐清的嗎 謝謝
So being const doesn’t say much for a reference, since they always are const, since they cannot rebind. This implies that const (int&) is effectively the same type as int&.大概是這樣?