There was a problem writing the copying class. The main object and its copy have a common memory address. How to separate them, while preserving the value in the main object and in its copy? Here is the code itself. Upon completion of the program gives an error as in the screenshot. Also tried to add exception handling. Underlines all BadIndex s. How to fix it?
#include <iostream> using namespace std; class INT { public: INT(unsigned _x, unsigned _y); INT(INT &I) :x(Ix), y(Iy), data(new int[x* y]) { data = &(I.data[1,2]); }; int& operator () (unsigned _x, unsigned _y); int operator () (unsigned _x, unsigned _y) const; ~INT(); private: unsigned x, y; int *data; }; inline INT::INT(unsigned _x, unsigned _y): x(_x), y(_y) { if (x == 0 || y == 0) throw BadIndex("Массив имеет нулевой размер"); data = new int[_x* _y]; } inline INT::~INT() { delete[] data; } inline int& INT::operator() (unsigned _x, unsigned _y) { if (_x >= x || _y >= y) throw BadIndex("Выбранный элемент находится вне массива"); return data[x*_x + _y]; } inline int INT::operator() (unsigned _x, unsigned _y) const { if (_x >= x || _y >= y) throw BadIndex("Выбранный элемент находится вне массива"); return data[x*_x + _y]; } int main() { INT a(10, 10); cin >> a(1,2); INT b(a); cout << "RESULT" << endl; cout << a(1, 2) << endl; cout << b(1, 2) << endl; return 0; } 