zoukankan      html  css  js  c++  java
  • 友元成员函数的简单应用

     1 #include <iostream>
     2 
     3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     4 using namespace std;
     5 class Date;
     6 class Time
     7 {
     8     public:
     9         Time(int,int,int);
    10         void display(Date &);
    11     private:
    12         int hour;
    13         int minute;
    14         int sec;
    15 };
    16 
    17 class Date
    18 {
    19     public:
    20         Date(int,int,int);
    21         friend void Time::display(Date &);
    22     private:
    23         int month;
    24         int day;
    25         int year;
    26 };
    27 
    28 Time::Time(int h,int m,int s)
    29 {
    30     hour=h;
    31     minute=m;
    32     sec=s;
    33 }
    34 
    35 void Time::display(Date &d)
    36 {
    37     cout<<d.month<<"/"<<d.day<<"/"<<d.year<<endl;
    38     cout<<hour<<":"<<minute<<":"<<sec<<endl;
    39 }
    40 
    41 Date::Date(int m,int d,int y)
    42 {
    43     month=m;
    44     day=d;
    45     year=y;
    46 }
    47 
    48 int main(int argc, char** argv) {
    49     Time t1(10,13,56);
    50     Date d1(12,25,2004);
    51     t1.display(d1);    
    52     return 0;
    53 }
  • 相关阅读:
    触发器
    dubbox 及 zookeeper的安装与启动
    负载均衡
    SOA架构
    获取短信验证码
    分步式
    saoruo
    Ngx
    redies技术
    Springboot开发特点
  • 原文地址:https://www.cnblogs.com/borter/p/9402031.html
Copyright © 2011-2022 走看看