看板 C_and_CPP 關於我們 聯絡資訊
最近再複習以前沒學好的東西 operator overloading裡面有幾樣東西我搞混了... 1. SparseMatrix& operator=(const SparseMatrix& ); -->return *this 2. SparseMatrix operator=(const SparseMatrix& ); -->return *this 這兩者之間有甚麼差別阿?? 另外以1為例 SparseMatrix& operator=(const SparseMatrix& sm){ this.xxx=sm.xxx; } 看過的範例的參數都是用 type&,假如我用type*呢??像下面這樣 SparseMatrix& operator=(const SparseMatrix* sm ){ this.xxx=sm->xxx; } 能不能過阿..? 謝謝 我剛剛試過了 不能過 我想是因為以a+b為例,b並不是指標,所以參數內只能用& ?? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.141.213 ※ 編輯: wk7 來自: 140.113.141.213 (10/14 10:31) ※ 編輯: wk7 來自: 140.113.141.213 (10/14 10:37) ※ 編輯: wk7 來自: 140.113.141.213 (10/14 10:42)
dendrobium:這跟overloading根本沒關係 你把指標和reference的章節 10/14 10:47
dendrobium:重看吧 10/14 10:47