友元成员函数写在一个cpp下时申明出错
求教高手,我把老师的几个类都写在demo.cpp下面,出问题了
#include <iostream> using namespace std; class Time{ friend void printTime1(Time &t); friend void Match::printTime2(Time &t); public: Time(int h,int m,int s){ Hour=h; Minute=m; Second=s; } private: int Hour; int Minute; int Second; }; void printTime1(Time &t){ cout<<t.Hour<<":"<<t.Minute<<":"<<t.Second<<endl; } class Match{ public: void printTime2(Time &t){ cout<<t.Hour<<":"<<t.Minute<<":"<<t.Second<<endl; } }; int main(){ Time t(3,9,11); printTime1(t); Match m; m.printTime2(t); }
编译说:‘Match’ has not been declared
我在前面加上
class Match;
编译又说:invalid use of incomplete type ‘class Match’
求教,写在一个cpp下应该怎么申明?