运行时出错
#include <iostream>
#include "stdlib.h"
#include "Time.h"
#include "Match.h"
using namespace std;
int main(void)
{
Match m(6,30,56);
m.testTime();
}
#include "Time.h"
#include <iostream>
using namespace std;
Time::Time(int hour,int min,int sec)
{
m_iHour = hour;
m_iMinute = min;
m_iSecond = sec;
}
void Time::printTime()
{
cout<<m_iHour<<"时"<<m_iMinute<<"分"<<m_iSecond<<"秒"<<endl;
}
#ifndef TIME_H
#define TIME_H
class Match;
class Time
{
friend Match;
public:
Time(int hour,int min,int sec);
private:
void printTime();
int m_iHour;
int m_iMinute;
int m_iSecond;
};
#endif
#ifndef STUDENT_H
#define STUDENT_H
#include "Time.h"
class Match
{
public:
Match(int hour,int min,int sec);
void testTime();
private:
Time m_tTimer;
};
#endif
#include "Match.h"
#include "Time.h"
#include <iostream>
using namespace std;
Match::Match(int hour,int min,int sec):m_tTimer(hour,min,sec)
{
}
void Match::testTime()
{
m_tTimer.printTime();
cout <<m_tTimer.m_iHour<<"-"<<m_tTimer.m_iMinute<<"-"<<m_tTimer.m_iSecond<<endl;
}E:\public\test\Time.h|7|error: a class-key must be used when declaring a friend|
E:\public\test\Time.h|7|error: friend declaration does not name a class or function|
和老师代码一样啊,是不是因为编译器的问题,我用的codeblock