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

posted on 2015-04-22 14:51  雨渐渐  阅读(799)  评论(0编辑  收藏  举报

导航