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++ 变量声明: 成员函数指针 成员变量指针
- C++第六周任务5:解决用一个项目多个文件的方式实现,其中两个类的声明放在一个.h文件中,每个类的成员函数分别放一个文件,main()函数用一个文件。体会这样安排的优点。
- C++中的const成员函数(函数声明后加const,或称常量成员函数)用法详解
- C++静态成员函数不能声明为const、volatile、virtual的原因 与 C++的对象模型
- C++ 友元一、成员函数、非成员函数和友元函数
- C++学习5-面向对象编程基础(构造函数、转换构造、静态数据成员、静态成员函数、友元)
- 成员函数声明为常量的解释--C++学习笔记
- C++之成员函数声明为虚函数的规则
- C++学习之const成员函数(函数声明后加const,或称常量成员函数)用法详解
- C++友元friend ——利用friend修饰符,可以让设定的外部函数访问对象中被保护数据
- 写程序说明C++中成员函数的初始化顺序只跟在类中的声明顺序有关, 而跟初始化列表中的顺序无关(笔试考过)
- C++之友元成员函数
- C++中的const成员函数(函数声明后加const,或称常量成员函数)用法详解
- C++ 静态成员函数使用不需要声明
- C++中的const成员函数(函数声明后加const,或称常量成员函数)用法详解
- C++友元friend --c++利用friend修饰符,可以让一些你设定的函数能够对这些保护数据进行操作
- C++中的const成员函数(函数声明后加const,或称常量成员函数)用法详解
- C++:如何声明和定义成员函数
- C++中的const成员函数(函数声明后加const,或称常量成员函数)用法详解
- C++中的const成员函数(函数声明后加const,或称常量成员函数)用法详解