1
12 7 C:Desktop\c&cpp\cpp.cpp [Error] 'int A::x' is private
#include<iostream>
#include<cstdio>
using namespace std;
class A{
public:
void display() { cout << x << endl;}
int getx(){ return x; }
private:
int x;
};
class B{
public:
void set(int i);
void display();
private:
A a;
};
void B::set(int i)
{
a.x = i;
}
int main()
{
B x;
return 0;
}
- 友元函数不是成员函数