[問題] operator overloading

看板C_and_CPP (C/C++)作者 (wk7)時間16年前 (2009/10/14 10:29), 編輯推噓0(002)
留言2則, 1人參與, 最新討論串1/6 (看更多)
最近再複習以前沒學好的東西 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)

10/14 10:47, , 1F
這跟overloading根本沒關係 你把指標和reference的章節
10/14 10:47, 1F

10/14 10:47, , 2F
重看吧
10/14 10:47, 2F
文章代碼(AID): #1ArJUExu (C_and_CPP)
文章代碼(AID): #1ArJUExu (C_and_CPP)