为什么将2个类放在同一个.cpp文件会出现错误呢
#include<iostream>
#include<string>
using namespace std;
class time
{
friend void printTime(time &t);//将printTime声明为time的友元函数
public:
time(int hour, int min, int sec)
{
this->hour = hour;
this->min = min;
this->sec = sec;
cout << "class time start" << endl;
}
private:
int hour, min, sec;
};
class match
{
public:
friend void printTime(time &t)
{
cout << t.hour << ":" << t.min << ":" << t.sec << endl;
}
};
int main()
{
time t(12, 0, 0);
match m;
m.printTime(t);
return 0;
}