Я получаю нарушение прав чтения при попытке построить решение. У меня есть класс матрицы, и я хотел бы прочитать матрицу из txt-файла (для работы). При отладке не было ошибок, но при попытке запустить программа, которую я получил "сообщение об исключении". Сообщение появляется в методе open1 в строке "matrix [i] [j]" - s.
{
template <class T>
bool Matrix<T> ::open1()
{
ifstream myfile("matrix1.txt");
if (!myfile)
{
cout << "Error in file opening" << endl;
return false;
}
myfile >> row;
myfile >> column;
for (int i = 0; i < row; i++)
{
for (int j = 0; j < column; i++)
{
myfile >> matrix[i][j];
}
}
myfile.close();
return true;
}
Вот класс
{
template<class T = double>
class Matrix
{
private:
unsigned row;
unsigned column;
T **matrix;
template<class OUTP>
friend std::ostream& operator<<(std::ostream&, const Matrix<OUTP>&);
template<class INP>
friend std::istream& operator>>(std::istream&, Matrix<INP>&);
public:
Matrix(unsigned = 0, unsigned = 0);
~Matrix();
Matrix(const Matrix<T>&);
void setMatrixElment(unsigned, unsigned, T);
void delMatrix();
unsigned getRow()const { return row; }
unsigned getColumn()const { return column; }
T getElement(unsigned = 0, unsigned = 0);
Matrix<T>& operator=(const Matrix<T>&);
Matrix<T> operator+(const Matrix<T>&);
Matrix<T> operator-(const Matrix<T>&);
Matrix <T>inverz();
bool open1();
bool open2();
Matrix<T> operator*(const double&);
Matrix<T> operator*(const Matrix<T>&);
T determinant() const;
};
}
Мой текстовый файл это
{
3 3
26.062000 16.600000 24.900000
49.800000 0.000000 1.000000
2.000000 4.000000 5.000000
Если я выделяю память, она все равно не читает элементы (я хорошо определил сложный класс, с типом проблем не было)
{
template <class T>
bool Matrix<T> ::open1()
{
ifstream myfile("matrix1.txt");
if (!myfile)
{
cout << "Error in file opening" << endl;
return false;
}
Matrix<Complex> b;
myfile >> b.row;
myfile >> b.column;
b.matrix = new T*[b.row];
for (unsigned i = 0; i < b.row; i++)
{
b.matrix[i] = new T[b.column];
}
for (int j = 0; j < b.row; j++)
{
for (int k = 0; k< b.column; k++)
{
myfile >> b.matrix[j][k];
}
}
myfile.close();
return true;
}
}