您的位置:首页 > 编程语言 > C语言/C++

Friend 非成员函数声明为友元 【C++ friend】

2012-10-01 13:22 330 查看
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

class Date {
public :
Date(int y, int m, int d);
friend void showDate(Date&);
private :
int year;
int month;
int day;
};
Date::Date(int y, int m, int d) {
year = y;
month = m;
day = d;
}
void showDate(Date& d) {
cout << d.year << '.' << d.month << '.' << d.day << endl;
}
int main() {
Date date1(2012, 3, 12);
showDate(date1);
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c++ date include system
相关文章推荐