Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Autor: Dawid Mocek
- */
- #include <string>
- #include <iostream>
- using namespace std;
- class Macierz
- {
- int **matrix;
- int x;
- int y;
- public:
- Macierz();
- Macierz(int x, int y);
- ~Macierz();
- friend ostream & operator<<(ostream &out, const Macierz& ma);
- Macierz& operator= (const Macierz&);
- };
- Macierz::Macierz() :x(0), y(0), matrix(nullptr)
- {
- }
- Macierz::Macierz(int x, int y) : x(x), y(y)
- {
- matrix = new int*[x];
- for (int c=0; c < x; c++)
- matrix[c] = new int[y];
- }
- Macierz::~Macierz()
- {
- if (matrix == nullptr) return;
- for (int c=0; c < x; c++)
- delete[] matrix[c];
- delete[] matrix;
- matrix = nullptr;
- }
- ostream & operator<<(ostream &out, const Macierz& ma)
- {
- for (int i = 0; i < ma.x; i++)
- for (int j = 0; j < ma.y; j++)
- out << ma.matrix[i][j] << " ";
- return out;
- }
- Macierz& Macierz::operator= (const Macierz& org)
- {
- // ten sam adres pamieci
- matrix = org.matrix;
- x = org.x;
- y = org.y;
- return *this;
- }
Advertisement
Add Comment
Please, Sign In to add comment