[求助]求助, 问一个关于const很弱的问题
#include <iostream>
using namespace std;
class mytime
{
public:
mytime(int h = 0, int m = 0);
void gettime(int& h, int& m) const;
//
mytime operator+(int min) const;
bool operator==(const mytime& t) const;
private:
int hour;
int minute;
};
mytime::mytime(int h, int m) :
hour(h), minute(m)
{}
void mytime::gettime(int& h, int& m) const{
h = hour;
m = minute;
}
///////////////////////////////////////////////////////////////////
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
mytime mytime::operator+(int min) const
{
mytime tmp(0,0);
tmp.minute = hour*60 + minute + min;
tmp.hour = tmp.minute / 60;
tmp.minute %= 60;
return tmp;
}
//== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
bool mytime::operator==(const mytime& t) const
{
if(t.hour == hour && t.minute == minute) return true;
else return false;
}
int main(){
int hh, mm;
mytime a(12, 20);
mytime b;
b=a+100;
b.gettime(hh,mm);
cout << hh << \":\" << mm;
}
bool mytime::operator==(const mytime& t) const
在这一行中有两个const, 我知道第一个const表示 mytime& t的t是不能更改的意思,但是第二个const是什么意思呢, 如果去掉地2个const会有什么不好呢?