1
說我有一個名爲Matrix的類,其中括號運算符已重載。我還有一個子類:childMatrix(從Matrix派生),括號操作符以不同的方式重載。使用父類的運算符而不是子類
我有一個對象childMatrix,但我想使用矩陣(父類)的運算符進行一些計算,這可能嗎?
我想:
childMatrix& m;
m(1,1) = 1; // works fine
(Matrix)m(1,1) = 1 //error
(Matrix&)m(1,1) = 1 // error (no match for ‘operator=’ (operand types are ‘Matrix’ and ‘int’))
謝謝!這解決了我的問題! – Winten