问题描述
- 用友元类外函数调用类的私有成员,显示无法调用,是什么原因
-
#include
#include
using namespace std;
class Date;
class Time
{
private:
int hour;
int minute;
int sec;
public:
Time(int h, int m, int s) :hour(h), minute(m), sec(s){}
friend void display(Time & , Date & );
};
class Date
{
private:
int month;
int day;
int year;
public:
Date(int h, int m, int s) :month(h), day(m), year(s){}
friend void display(Time &, Date &);
};
void dispaly(Time & t, Date & d)
{
cout << d.month << "/" << d.day << "/" << d.year << endl;
cout << t.hour << ":" << t.minute << ":" << t.sec << endl;}
void main()
{
Time t1(12, 13, 14);
Date d1(6, 12, 2016);
dispaly(t1, d1);
system("pause");
}
解决方案
我晕,看了好久没看出问题来
后来发现是void dispaly(Time & t, Date & d)中的dispaly拼错了,应该是display
解决方案二:
php,类外函数调用类的成员函数的方法
时间: 2024-12-05 04:35:01