是否有可能重載operator +C++,重載操作符+矩陣
template <typename U>
Mat <T> operator + (const Mat <U> &A);
以下矩陣運算
Matrix (1,1) + scalar = scalar
scalar + Matrix (1,1) = scalar
Matrix(1,1) + Matrix(1,1) = scalar
和語法(或類似)?
template <typename T, typename U>
T operator + (const Mat <U> &M) const;
更新問題:
尺寸作爲模板參數:
template <typename T, typename U, const unsigned int TDim>
T operator + (const Mat <U> &M, TDim <dim>) const;
與專業化爲昏暗= 1
template <typename T, typename U>
T operator + (const Mat <U> &M, TDim <1>) const;
是的。你試過了嗎? –