zoukankan      html  css  js  c++  java
  • 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;
    }

  • 相关阅读:
    设计模式
    IPC- Posix与system v
    squashfs文件系统
    各种根文件系统
    SPI通讯协议
    tty各种设备的情况
    Linux系统调用过程
    uImage和zImage的区别
    jquery可见性选择器(匹配匹配所有显示的元素)
    jquery可见性选择器(匹配所有隐藏的元素)
  • 原文地址:https://www.cnblogs.com/i80386/p/4447464.html
Copyright © 2011-2022 走看看