classA{public:staticintnumber;friendvoidhanshu();};voidhanshu(){cout<<A::number;}intA::number=456;//注意这里,你对静态成员初始化有错误intmain(){Aa;hanshu();system("pause");}还要注意,并不是友元函数能访问类中的所有成员,这样理解是错误的,正确的理解是,友元函数能通过类的对象访问类中的所有成员,友元函数是不能直接访问类中的私有成员的,比如classA{inta;public:friendvoidf();}voidf(){a=1;}//这样就会出错,只能通过类的对象来访问,比如voidf(){Ama;ma.a=1;}//这样就正确,如果函数f不是友元,则ma.a是错误的。