討論串[問題] operator overloading
共 6 篇文章
內容預覽:
當你這樣寫的時候. [修正]. - 實際上是呼叫一次 copy-assignment (oTest.GetList). - 以及一次 copy-constructor. - 不過前面那個 copy-assignment 被 RVO 消掉了. - 所以沒呼叫到 List::operator=. [/修
(還有352個字)
內容預覽:
List Test::GetList(). {. return m_oList;. }. Test oTest;. List oList = oTest.GetList();. 這樣子做還是會取得 m_oList, 等於 oList 是 m_oList 的別名. 那修改 oList 就會改到 m_o
(還有1390個字)
內容預覽:
怎麼覺得兩個同時寫在 class 中,會 compile 不過。. 想法參考自:. class A {. A method(const A&) {return *this;}. A& method(const A&) {return *this;}. };. 這樣寫 compiler 會回應有錯吧。
(還有757個字)
內容預覽:
大概是你搞錯了, 應該不會 return this. 你這兩個 overload 要 return 的都是 SparseMatrix,. 除非你碰巧有一個 ctor 是 SparseMatrix(SparseMatrix*). 我記得好像 compiler 會自動幫你用這 ctor (不肯定). 可
(還有130個字)