是否可以为Matrix类实现move operator + / operator- / operator *?

问题描述 投票:0回答:1

我正在考虑如何通过加(减)和乘运算来定义一类实数矩阵NxN。我正在寻找有效的内存使用情况。


class Matrix {
private:
    std::size_t _size_n;
    double **_pMatrix;

public:
    Matrix(const size_t n);

    ~Matrix();

    double &operator()(size_t, const size_t);

    double operator()(size_t, const size_t) const;

    size_t size_n() const { return _size_n; }

};

std::ostream &operator<<(std::ostream &, const Matrix &);

Matrix operator+(const Matrix&, const Matrix&);
Matrix operator-(const Matrix&, const Matrix&);
Matrix operator*(const Matrix&, const Matrix&);```
c++ matrix move operator-keyword memory-efficient
1个回答
0
投票

是的,您可以有其他重载

Matrix operator+(const Matrix&, Matrix&&);
Matrix operator+(Matrix&&, const Matrix&);
Matrix operator+(Matrix&&, Matrix&&);

要重新使用临时存储器之一。

© www.soinside.com 2019 - 2024. All rights reserved.