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;
    }

  • 相关阅读:
    怎么安装Python?
    Ramnit蠕虫病毒分析和查杀
    Exphub[漏洞利用脚本库]
    SMBv3远程代码执行漏洞复现(CVE-2020-0796)
    Tomcat AJP 文件包含漏洞复现(CVE-2020-1938)
    Fastjson远程代码执行漏洞复现
    信息收集之——旁站、C段
    Redis未授权访问漏洞复现与利用
    CSS
    MVC控制器路由
  • 原文地址:https://www.cnblogs.com/i80386/p/4447464.html
Copyright © 2011-2022 走看看