#include <iostream>
using namespace std;
class CBase
{
public:
int a;
int b;
private:
int c;
int d;
protected:
int e;
int f;
//friend int cout1();
};
class CDerived : public CBase
{
public:
friend class CBase;
int cout1()
{
cout << "a" << endl;
cin >> a;
cout << "b" << endl;
cin >> b;
cout << "c" << endl;
cin >> c;
cout << "d" << endl;
cin >> d;
cout << "e" << endl;
cin >> e;
cout << "f" << endl;
cin >> f;
cout << a << "" << b << "" << c << "" << d << "" << e << "" << f << "" << endl;
}
};
int main()
{
CDerived chi;
chi.cout1();
}
フレンドクラスとフレンド機能の使い方は?私を助けてください。私は多くの同様のエラーがあります:
c6.cpp: In member function int CDerived::cout1():
c6.cpp:10: error: int CBase::c is private
c6.cpp:30: error: within this context
c6.cpp:11: error: int CBase::d is private
c6.cpp:32: error: within this context
c6.cpp:10: error: int CBase::c is private
c6.cpp:37: error: within this context
c6.cpp:11: error: int CBase::d is private
c6.cpp:37: error: within this context