0
#include <cassert>
#include <iostream>
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
template <class T> class Matrix;
template <class T>
class Matrix
{
public:
friend istream& operator>>(istream& inStream,Matrix& other)
{
string line ;
T x ;
unsigned _rows = 0 , _cols = 0 ;
while(inStream.good())
{
while(getline(inStream,line))
{
istringstream streamA(line) ;
_cols = 0;
while(streamA >> x)
{
matrix[_rows][_cols] = x ;
_cols++ ;
}
_rows++ ;
}
}
return inStream ;
}
Matrix(unsigned r, unsigned c);
Matrix(const Matrix<T>& rhs);
~Matrix();
const Matrix operator=(const Matrix& other);
void output() const ;
// Matrix mathematical operations: insert overloaded operator signatures
// Access the individual elements of a matrix: insert overloaded operator signatures
// Getters:
unsigned getRows() const; // Return number of rows
unsigned getCols() const; // Return number of columns
private:
Matrix();
T ** matrix; // the matrix array
unsigned rows; // # rows
unsigned cols; // # columns
위의 파일은 .h 파일입니다. >> 연산자를 오버로드하려고합니다. "친구 istream & 연산자 (istream & inStream, 매트릭스 & 기타)"function 텍스트 파일에서 데이터를로드하려고하지만 계속해서 invalid use of non-static data member
오류가 발생합니다.템플릿 친구 기능과 함께 비 정적 데이터 멤버 오류가 잘못되었습니다. C++
'matrix [_rows] [_ cols] = x'' 대신에'other.matrix [_rows] [_ cols]'를 의미했을 수도 있습니다. –