怎么成员函数的友员函数老是报错
如下:
MyTime.h
#include "Match.h"
class MyTime
{
//friend void printTime(MyTime &t); //全局函数的友元函数
friend void Match::printTime(MyTime &t); //成员函数的友元函数
... }
Match.h
class MyTime; //成员函数的友元函数
class Match
{
public:
Match();
virtual ~Match();
void printTime(MyTime &t); //成员函数的友元函数
};
Match.cpp
void Match::printTime(MyTime &t)
{
//cout << "Time: " << t1.m_iHour << ":" << t1.m_iMinute << ":" << t1.m_iSecond << endl;
cout << t.m_iHour << endl;
}
main函数:
MyTime t(18,25,30);
Match m;
m.printTime(t);错误是:
~\Match.cpp|18|error: invalid use of incomplete type 'class MyTime'|
include\Match.h|4|error: forward declaration of 'class MyTime'|