//testMain1.cpp
//隐式和显式使用this指针来访问对象的数据成员
#include <iostream>
using namespace std;
class Test
{
public:
Test(int = 0);
void print() const;
private:
int x;
};
Test::Test(int val)
:x(val)
{}//空函数体
void Test::print() const
{
cout << "x = " << x << endl;
cout << "this->x = " << this->x << endl; //两种表示方法,谨记
cout << "(*this).x = " << (*this).x << endl;
}
int main()
{
Test shortTest(9);
shortTest.print();
system("pause >> cout");
return 0;
}
//Time.h
#ifndef TIME_H_
#define TIME_H_
class Time
{
public:
Time(int = 0,int = 0,int = 0);
Time &setTime(int,int,int);
Time &setHour(int);
Time &setMinute(int);
Time &setSecond(int);
int getHour() const;
int getMinute() const;
int getSecond() const;
void printUniversal() const;//传统的计时方式,0-23时
void printStandard() const;//普遍的计时方式0-12;AM,PM
private:
int hour;//0-23
int minute;//0-59
int second;//0-59
};
#endif