我收到了一個我無法解釋的錯誤。這裏是我的頭文件:與朋友功能無法訪問的會員
#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