在c++中,能同时在两个不同的类中定义雷同的友元函数吗

在c++中,能同时在两个不同的类中定义相同的友元函数吗?
在c++中,能同时在两个不同的类中定义相同的友元函数吗?今天在上实验课的时候,在vc++ 6.0运行此程序,总是出现
:\Windows\System32\Cpp1.cpp(39) : error C2248: 'month' : cannot access private member declared in class 'Date'
        C:\Windows\System32\Cpp1.cpp(20) : see declaration of 'month'#include<iostream>这个错误。。求解答,,,在c++中,能同时在两个不同的类中定义雷同的友元函数吗
using namespace std;
class Date;
class Time
{
public:
Time(int, int,int);
friend void display(Time &,Date &);
private:
int hour;
int minute;
int sec;
};
class Date
{
public:
Date(int,int,int);
friend void display(Time &,Date &);
private:
int month;
int day;
int year;
};
Time::Time(int h,int m,int s)
{
hour=h;
minute=m;
sec=s;
}
Date::Date(int m,int d,int y)
{
month=m;
day=d;
year=y;  
}

void display(Date &d,Time &t)
{
cout<<d.month<<"/"<<d.day<<"/"<<d.year<<endl;
cout<<t.hour<<":"<<t.minute<<":"<<t.sec<<endl;
}
int main()
{
Time t1(10,13,56);
Date d1(12,25,2004);
display(d1,t1);
return 0;
}
------解决思路----------------------
你的声明是friend void display(Time &,Date &);,但是实现是void display(Date &d,Time &t),这两个重载了,函数参数的类型和顺序不要搞错!
------解决思路----------------------
已测,在vs2012中没问题,能正确输出,编译器问题,VC6对C++支持可能比较落后点。

class B;

class A
{
public:
A(){x = 11;}
friend void display(A& a, B& b);
private:
int x;
};

class B
{
public:
B(){x = 12;}
friend void display(A& a, B& b);
private:
int x;
};

void display(A& a, B& b)
{
printf("====%d\n", a.x);
printf("====%d\n", b.x);
}

int _tmain(int argc, _TCHAR* argv[])
{

A a;
B b;
display(a, b);

return 0;
}

------解决思路----------------------
2楼正解。。。没发现LZ写错了。。