// Test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream.h>
class A;
class B
{
public:
void print_a(A&);
};
class A{
public:
A(int I):i(I){}
private:
friend void B::print_a(A&);
int i;
};
//----------------------------------------------------------------------
//友元并不是自己拥有,而是属于别人的函数,但是可以把他设置成能够访问自己私有变量
void B::print_a(A& val)
{
cout<<val.i<<endl;
}
int main(int argc, char* argv[])
{
A i(10);
B b;
b.print_a(i);
return 0;
}