pch.h文件:
class Clock
{
private:
int hour;
int minute;
int second;
public:
void SetTime(int h, int m, int s);
Clock(Clock& c);
Clock(int h, int m, int s);
~Clock(void);
void ShowTime();
};
pch.cpp文件
#include "pch.h"
#include<iostream>
using namespace std;
Clock::Clock(Clock& c)
{
hour = c.hour;
minute = c.minute;
second = c.second;
cout << "The new clock: ";
ShowTime();
cout << " is copy constructed" << endl;
}
Clock::Clock(int h, int m, int s)
{
hour = h;
minute = m;
second = s;
cout << "The new clock: ";
ShowTime();
cout << " is constructed!" << endl;
}
Clock::~Clock(void)
{
cout << "The clock: ";
ShowTime();
cout << " is destructed" << endl;
}
void Clock::SetTime(int h, int m, int s)
{
hour = h;
minute = m;
second = s;
}
void Clock::ShowTime()
{
cout << hour << ":" << minute << ":" << second;
}
clock.cpp文件:
#include "pch.h"
#include <iostream>
using namespace std;
Clock Ring(Clock c)
{
c.ShoweTime();
cout << "Clock is ringing!" << endl;
return c;
}
//Clock Ring(Clock c)
//{
// c.ShowTime();
// cout << "Clock is ringing!" << endl;
// return c;
//}
void main()
{
Clock c1(11, 20, 30);
c1.ShowTime();
cout << endl;
Ring(c1);
system("pause");
}