• c++ 私有函数 头文件设计


    clock.h
    
    #ifndef CLOCK_H_INCLUDED
    #define CLOCK_H_INCLUDED
    
    class Clock
    {
    public:
      static void HandleExdataResponse(..........); 静态成员实现方式跟其他函数一样。只需在这里标明为static即可。
    public: Clock(int id); Clock(Clock &c); Clock(int id, int h, int m, int s); void setTime(int h,int m, int s); void showTime(); private: bool checkTime(int h, int m, int s); private: int id; int Hour, Minute, Second; public: ~Clock(void); }; #endif // CLOCK_H_INCLUDED
    clock.cpp
    
    
    #include"clock.h"
    #include"iostream"
    using namespace std;
    Clock::Clock(int number)
    {
        id = number;
    }
    
    Clock::Clock(int number, int h,int m, int s)
    {
        id = number;
        setTime(h, m, s);
    }
    
    Clock::Clock( Clock &c )
    {
        this->id = c.id;
        setTime(c.Hour, c.Minute, c.Second);
    }
    
    void Clock::setTime(int h,int m, int s)
    {
        if (checkTime(h, m, s)) {
            Hour   = h;
            Minute = m;
            Second = s;
        }
    }
    
    void Clock::showTime()
    {
        cout<<"clock"<<id<<"->"<<Hour<<":"<<Minute<<":"<<Second<<"
    ";
    }
    
    Clock::~Clock(void)
    {
        cout<<"clock"<<id<<" closed
    ";
    }
    
    
    bool Clock::checkTime( int h, int m, int s )
    {
        return true;
    }
    #include <iostream>
    #include "clock.h"
    using namespace std;
    
    int main()
    {
        Clock clock1(1);
        clock1.showTime();
        clock1.setTime(8,30,30);
        clock1.showTime();
        return 0;
    }

  • 相关阅读:
    POJ 2027
    POJ 2017
    重定位(转载)
    常见储存器件的分辨(RAM、SRAM、SDRAM、ROM、FLASH、Nand Flash、Nor Flash、DDR、eMMC)
    虚拟机安装配置ubuntu共享文件夹
    ARM芯片时钟体系
    串行通信协议 —— UART
    串行通信协议——基础知识
    内存地址和内存空间
    中断与异常
  • 原文地址:https://www.cnblogs.com/i80386/p/4447464.html
Copyright © 2020-2023  润新知