常量类只能调用常量函数,对于普通的类的函数可以调用常量函数,
常量数据成员的定义只能在类的外面进行初始化,
#include<iostream>
using namespace std;
class time{
private:
int hour, minute, second;
public:
time(int h, int m, int s)
{
hour = h;
minute = m;
second = s;
}
void showtime() const;
};
void time::showtime()const
{
cout << hour << " " << minute << ":" << second << endl;
}
void main()
{
const time meeting(2, 4, 5);
meeting.showtime();
time classtime(4, 5, 6);
classtime.showtime();
system("pause");
}