에서 친구 함수에서 클래스에 선언 된 보호 된 멤버에 액세스 할 수 없습니다 :다음과 같이 내가 기본 클래스를했습니다 파생 클래스
은 C를 컴파일 // 파생 클래스 - polynomialType.h#include "arrayListType.h"
class polynomialType: public arrayListType<double>
{
friend ostream& operator<<(ostream& ,const polynomialType&);
friend istream& operator>>(istream& ,polynomialType&);
public:
polynomialType operator+(const polynomialType&);
polynomialType operator-(const polynomialType&);
//polynomialType operator*(const polynomialType&);
double operator() (double x);
polynomialType(int size = 100);
int min(int x,int y) const;
int max(int x,int y) const;
};
그러나 이후
오데, 나는 오류가있어;
error C2248: 'arrayListType<elemType>::length' : cannot access protected member declared in class 'arrayListType<elemType>'
나는 해결책을 찾았지만 찾을 수 없습니다. 운영자 >>의 정의가 설명을 위해 제공됩니다.
istream& operator>>(istream is,polynomialType& p)
{
cout << "the degree of this polynomial is" << p.length-1 << endl;
for (int i = 0; i < p.length; i++)
{
cout << "enter coefficient of x^" << i <<": ";
is >> p.list[i];
}
return is;
}
오류는 친구 기능에 대해서만 표시됩니다. 왜 그렇습니까 ??
'public' 정의에'friend' 함수를 넣으려고 했습니까? –
'friend' 선언은 특정 액세스 한정자 아래에있을 필요는 없습니다. – inetknght