Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Matrix.hpp
- #pragma once
- namespace Furdarius
- {
- const int MATRIX_MAX_SIZE = 100;
- struct Size {
- int row, col;
- };
- template<typename _T>
- class Matrix
- {
- Size size;
- _T data[MATRIX_MAX_SIZE][MATRIX_MAX_SIZE];
- public:
- Matrix(void)
- {
- size.row = MATRIX_MAX_SIZE;
- size.col = MATRIX_MAX_SIZE;
- };
- Matrix(int row, int col)
- {
- size.row = row;
- size.col = col;
- };
- Matrix(Size _size)
- {
- size.row = _size.row;
- size.col = _size.col;
- };
- Matrix(Matrix &source, int num)
- {
- size = source.getSize();
- for (int i = 0; i < size.row; ++i)
- for (int j = 0; j < size.col; ++j)
- data[i][j] = source[i][j] + num;
- };
- Size getSize() {
- return size;
- };
- _T* operator[](int id) {
- return data[id];
- };
- const _T* operator[](int id) const {
- return data[id];
- };
- operator double() const {
- double res = 0;
- for (int i = 0; i < size.row; ++i)
- for (int j = 0; j < size.col; ++j)
- res += data[i][j];
- return res / (size.row * size.col);
- };
- friend const Matrix<_T> operator+(const Matrix<_T>& left, const Matrix<_T>& right);
- friend const Matrix<_T> operator-(const Matrix<_T>& left, const Matrix<_T>& right);
- ~Matrix()
- {
- size.row = 0;
- size.col = 0;
- }
- };
- template<typename _T>
- const Matrix<_T> operator+(const Matrix<_T>& left, const Matrix<_T>& right) {
- Matrix<_T> res(left.getSize());
- for (int i = 0; i < res.getSize().row; ++i)
- for (int j = 0; j < res.getSize().col; ++j)
- res[i][j] = left[i][j] + right[i][j];
- return res;
- };
- template<typename _T>
- const Matrix<_T> operator-(const Matrix<_T>& left, const Matrix<_T>& right) {
- Matrix<_T> res(left.getSize());
- for (int i = 0; i < res.getSize().row; ++i)
- for (int j = 0; j < res.getSize().col; ++j)
- res[i][j] = left[i][j] - right[i][j];
- return res;
- };
- };
- // В main.cpp есть код сложения
- Matrix<MatrixType> addRes = first + second;
- // тут first и second это тоже матрицы Matrix<MatrixType>
- /*
- Линковщик ругается:
- 1>main.obj : error LNK2019: unresolved external symbol "class Furdarius::Matrix<int> const __cdecl Furdarius::operator+(class Furdarius::Matrix<int> const &,class Furdarius::Matrix<int> const &)" (??HFurdarius@@YA?BV?$Matrix@H@0@ABV10@0@Z) referenced in function _main
- */
Advertisement
Add Comment
Please, Sign In to add comment