这个程序和老师讲的一样,我只不过写在一块了为啥不能访问private?是编译器的问题吗?我用的vs2013
#include<iostream>
#include<stdlib.h>
using namespace std;
class Time
{
friend void Match::printTime(Time &t);
public:
Time(int hour, int min, int sec);
private:
int m_iHour;
int m_iMinute;
int m_iSecond;
};
Time::Time(int hour, int min, int sec)
{
m_iHour = hour;
m_iMinute = min;
m_iSecond = sec;
}
class Time;
class Match
{
public:
void printTime(Time&t);
};
void Match::printTime(Time&t)
{
cout << t.m_iHour << ":" << t.m_iMinute << ":" << t.m_iSecond << endl;
}
int main(void)
{
Time t(4, 45, 56);
Match m;
m.printTime(t);
system("pause");
return 0;
}