[問題] 多載<<無法印出後置++的物件
遇到的問題:自定義的Date物件d, 我用多載做d++將日期加一
並用多載的<<做 cout<<d++
但過不了編譯器
程式跑出來的錯誤結果:無法編譯
http://paste.plurk.com/show/275825/
這是錯誤訊息
開發平台:Dev-C++
有問題的code:(class Date中有private成員day)
多載++:
Date Date::operator++(int)
{
Date temp = *this;
day++;
return temp;
}
多載<<:
ostream& operator<<(ostream& output, Date& d)
{
output<<d.day;
return output;
}
.h 的code: http://paste.plurk.com/show/275831
.cpp的code: http://paste.plurk.com/show/275830 (++, <<, 相關的函式在最下方)
main : http://paste.plurk.com/show/275832
補充說明:這是書本的範例, 我沒有更動程式碼
實在看不出來有什麼問題..煩請幫我抓抓看問題在哪裡:)
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 210.69.128.66
→
07/01 15:47, , 1F
07/01 15:47, 1F
※ 編輯: jehovah 來自: 210.69.128.66 (07/01 15:56)
→
07/01 15:57, , 2F
07/01 15:57, 2F
→
07/01 16:17, , 3F
07/01 16:17, 3F
→
07/01 16:19, , 4F
07/01 16:19, 4F
→
07/01 16:20, , 5F
07/01 16:20, 5F
→
07/01 17:00, , 6F
07/01 17:00, 6F
→
07/01 17:02, , 7F
07/01 17:02, 7F
推
07/01 21:08, , 8F
07/01 21:08, 8F
→
07/01 21:11, , 9F
07/01 21:11, 9F
→
07/01 21:12, , 10F
07/01 21:12, 10F
→
07/01 22:07, , 11F
07/01 22:07, 11F
→
07/01 22:07, , 12F
07/01 22:07, 12F
→
07/01 22:28, , 13F
07/01 22:28, 13F
→
07/02 08:47, , 14F
07/02 08:47, 14F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章