C++友元函数的问题,求C++高手指点!

#include<iostream>
#include<string>
using namespace std;
class whw
{
private:
int Age;
friend void whbsb(const whw& wxk);
public:
whw(int InputAge)
{
Age=InputAge;
}
};
friend void whbsb(const whw& wxk)
{
cout<<"年龄="<<wxk.Age<<endl;
}
int main()
{
whw lsh(50);
return 0;
}

我在类中声明了一个友元函数,并且在类外进行了实现!但是编译没有通过,不知道是什么语言啊!
error C2255: 'whbsb' : a friend function can only be declared in a class
求指点,能解决问题的,一定采纳!

第1个回答  2014-10-21
友元只在声明的时候需要关键字 friend
定义时不需要
第2个回答  2014-10-21
friend void whbsb(const whw& wxk)  //这个前面的friend去掉
  { cout<<"年龄="<<wxk.Age<<endl;}

追问

我也发现了,真实罪过啊!

本回答被提问者采纳
第3个回答  2014-10-21
友元函数的定义只能在类中
相似回答