Ошибка доступа к членам класса С++
#include <iostream>
using namespace std;
template <typename T> class Matrix
{
private:
T** arr;
int rows, cols;
public:
};
template <typename T>
T min(Matrix<T>& a)
{
T minimal = a.arr[0][0];
for (int i = 0; i < a.GetRows(); i++)
{
for (int j = 0; j < a.GetCols(); j++)
{
if (a.arr[i][j] < a.arr[i][j + 1])
{
if (j >= a.GetCols())
{
continue;
}
minimal = a.arr[i][j];
}
}
}
return minimal;
}
int main()
{
Matrix<Fraction> a(2, 2);
cout << "Enter 4 array elements of fractions:" << endl << "(sign, unit, num, denom)";
cin >> a;
cout << a << endl;
cout << endl << min(a);
return 0;
}
Проблема такая: при вызове функции min() выводит ошибку (Matrix::arr: невозможно обратиться к private член(а конкретно к a.arr), объявленному в классе "Matrix")
Ответы (1 шт):
Автор решения: Kaktuts
→ Ссылка
Либо сделайте arr public, либо допишите публичный метод геттер, типа
T GetValueByIndex(const size_t i, const size_t j) const {
....
}