我正在處理一個通用的矩陣類。 我重載+功能,這樣,當是做:模板函數重載C++
- 矩陣=標量*矩陣
- 矩陣=矩陣*標量
- 矩陣=矩陣*矩陣
試圖做它就像那樣(函數重載): 這是一個正確的方法嗎?
template<class T>
class Matrix
{
std::vector< std::vector<T> > mat;
size_t rows , cols;
public:
Matrix(){}
Matrix(const std::string){ }
Matrix(const size_t r, const size_t c, const std::vector<T> v){ }
Matrix(const Matrix& other);
Matrix<T> operator=(const Matrix<T> &other) { }
Matrix<T> operator+(const Matrix<T> &other) const{}
friend Matrix<T> operator*(const T &mat, const Matrix<T> &scalar) { }
friend Matrix<T> operator*(const Matrix<T> &mat, const T &scalar) { }
friend Matrix<T> operator*(const Matrix<T> &mat, const Matrix<T> &other) { }
此外,我會很高興知道,如果我的聲明有一些問題。 感謝您的幫助。
提醒:您需要在頭文件中執行執行和聲明 – Gabriel
這將是很好的顯示您的問題,而不是請求代碼審查。 – Emadpres
我懷疑你的賦值操作符應該返回'Matrix&'。另外,不知道爲什麼'std :: string'在那個alternate-ctor中是'const';嘗試一個const引用。 – WhozCraig