[问题] 利用overloding计算两个日期相差几天

楼主: ununnihao (安安你好)   2015-05-01 04:46:06
开发平台(Platform): (Ex: VC++, GCC, Linux, ...)
GCC
问题(Question):
In function 'const int operator-(const myDate&, const myDate&)':
101-21 [Error] passing 'const myDate' as 'this' argument of
'int myDate::dayOfYear()' discards qualifiers [-fpermissive]
102-21 [Error] passing 'const myDate' as 'this' argument of
'int myDate::dayOfYear()' discards qualifiers [-fpermissive]
程式码(Code):(请善用置底文网页, 记得排版)
http://ideone.com/BNMlxw
补充说明(Supplement):
我用operator overloding 要算出两个日期相差几天
目前的问题就是不知道哪里出错一直编译不过
我有找到如果把friend const int operator
-(const myDate& day1 , const myDate& day2)
其中括号里的两个const拿掉就会过
但一直想不通为啥。
作者: yvb   2015-05-01 05:18:00
int dayOfYear() const; bool isLeap(int year) const;否则强制转型(不建议): x = ((myDate)day1). ... y = ...

Links booklink

Contact Us: admin [ a t ] ucptt.com