问题遇到的现象和发生背景
已有部分代码,只需补充后运行
问题相关代码,请勿粘贴截图
#ifndef MATRIX
#define MATRIX
#include
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
class Matrix
{
public:
Matrix(cv::Mat mat)
: obj_(mat)
{}
Matrix add(const Matrix& m);
Matrix sub(const Matrix& m);
Matrix multiply(const Matrix& m);
Matrix& operator=(const Matrix& m);
void print() {
std::cout << obj_ << std::endl;
};
private:
cv::Mat obj_;
};
Matrix Matrix::add(const Matrix& m)
{
}
Matrix Matrix::sub(const Matrix& m)
{
}
Matrix Matrix::multiply(const Matrix& m)
{
}
Matrix& Matrix::operator=(const Matrix& m)
{
obj_.release();
obj_ = m.obj_.clone();
return *this;
}
#endif // MATRIX
int main(int argc, char* argv[])
{
cv::Mat m1 = (cv::Mat_(3, 3) << -1, 0, 1, -2, 0, 2, -1, 0, 1);
cv::Mat m2 = (cv::Mat_(3, 3) << -1, -2, -1, 0, 0, 0, 1, 2, 1);
Matrix x(m1), y(m2);
Matrix a = x.add(y);
a.print();
Matrix b = x.sub(y);
b.print();
Matrix c = x.multiply(y);
c.print();
return 0;
}