설명 할 수없는 오류가 발생했습니다.친구 기능을 사용하여 액세스 할 수없는 멤버
#include <iostream>
using namespace std;
namespace project
{
#ifndef MATRIX_H
#define MATRIX_H
typedef int* IntArrayPtr;
class Matrix
{
public:
friend ostream& operator<<(ostream& out, const Matrix& object);
friend istream& operator>>(istream& in, Matrix& theArray);
//Default Constructor
Matrix();
Matrix(int max_number_rows, int max_number_cols, int intial_value);
//Destructor
~Matrix();
//Copy Constructor
Matrix(const Matrix& right_side);
//Assignment Operator
Matrix& operator=(const Matrix& right_side);
void Clear();
int Rows();
int Columns();
bool GetCell(int x,int y, int& val);
bool SetCell(int x,int y, int val);
//void Debug(ostream& out);
private:
int initialVal;
int rows;
int cols;
IntArrayPtr *m;
};
#endif
}
그리고 여기 내 정의 : : 여기 내 헤더 파일입니다
ostream& operator<<(ostream& out, const Matrix& object)
{
for(int r = 0; r < object.rows; r++)
{
for(int c = 0; c < object.cols; c++)
{
out << object.m[r][c] << " ";
}
out << endl;
}
return out;
}
그것은 나에게 Matrix.h 구성원이 액세스 할 수없는 것을 오류를주고, 그러나 나는 명확하게 친구 기능이 있음을 밝혔다.
나는 당신이 당신의 헤더에있는 클래스와 같은 네임 스페이스의 구현을 두지 않았기 때문에 당신이 내기. – dasblinkenlight
그 정의가 클래스 안에 있습니까? – smac89
dasblinkenlight가 옳았습니다. 모든 빠른 응답 주셔서 감사합니다! – user3112739