herrDeng網內搜尋

自訂搜尋

Ads

2016年12月29日 星期四

C++的泛型樣版(Generic Template)與矩陣Matrix(寫在自訂標頭檔




2 則留言:

B10133186 提到...

friend Matrix operator^(Matrix& A, Matrix& B)
{
Matrix C(A.row, A.col);
for (int i = 0; i < A.row; i++) {
for (int j = 0; j < A.col; j++)
C(i, j) = (T)((T)A(i, j) ^ (T)B(i, j));
}
return C;
}
friend Matrix& operator*(Matrix A, Matrix B)
{
for (int i = 0;i < A.row;i++) {
for (int j = 0;j < B.col;j++) {
C(i, j) = 0;
for (int k = 0;k <A.col;k++)
C(i, j) += A(i, k)*B(k, j);
}
}
return C;
}

B10233077 提到...

friend Matrix operator^(Matrix& A, Matrix& B)
{
Matrix C(A.row, A.col);
for (int i = 0; i < A.row; i++) {
for (int j = 0; j < A.col; j++)
C(i, j) = (T)((T)A(i, j) ^ (T)B(i, j));
}
return C;
}
friend Matrix& operator*(Matrix A, Matrix B)
{
for (int i = 0;i < A.row;i++) {
for (int j = 0;j < B.col;j++) {
C(i, j) = 0;
for (int k = 0;k <A.col;k++)
C(i, j) += A(i, k)*B(k, j);
}
}
return C;
}

Related Posts Plugin for WordPress, Blogger...

熱門文章