我正在处理一个通用的矩阵类。 我重载+功能,这样,当是做:模板函数重载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