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<<"\n";
}

Clock::~Clock(void)
{
    cout<<"clock"<<id<<" closed\n";
}


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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值