#include<iostream>
using namespace std;
class Time
{
public(int ,int,int );
void show_Time();
void reset_time();
private:
int hour;
int minute;
int sec;
};
Time::Time(int h,int m,int s)
{
hour=h;
minute=m;
sec=s;
}
void Time::show_Time()
{
count<<hour<<":"<<minute<<":"<<sec<<endl;
}
.........//省略写
容易容混的几个概念
1:常对象 (以上述代码为例)Time const t;
2:常成员函数 void Time::fun()const;不能修改类中数据成员。
3:常指针:Time *const p;p的指向不能改变。
4:常对象指针:const Time *p;类对象的值不能通过指针来实现。
5:对象的动态创建与释放: Time *p=new Time(int ,int,int );
6:对象的复制和赋值:t1=t2;把后者赋值给前者,而不是对成员函数赋值。