[問題] 新手程式碼問題

看板C_and_CPP作者 (絲凱56)時間10年前發表 (2015/06/01 16:35), 10年前編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) codeblock 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 這是我們學校講義上的小範例 http://codepad.org/Ci48qY9q 然後要練習擴充裡面的class cPoint 增加函數XplusY回傳該物件x與y值的和 我一開始的想法是這樣 http://codepad.org/ZB7ocXQ8 加入 void XplusY(); voidcPoint::XplusY(){xy=x+y;} main裡面加入 xy=p1.XplusY(); cout<<xy<<endl; 餵入的資料(Input): 預期的正確結果(Expected Output): 應該會跑出7 錯誤結果(Wrong Output): 1. xy=p1.XplusY();->這行出錯 line22 void value not ignored as it ought to be 2.void cPoint::XplusY(){xy=x+y;} 這行出錯原因是沒宣告xy,我在private內宣告double xy就OK 但是其實我不知道是不是該宣告在那邊 程式碼(Code):(請善用置底文網頁, 記得排版) 補充說明(Supplement): 感謝各位神人看完小弟新手題QQ希望可以幫忙解答 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.171.148.13 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1433176517.A.565.html

06/02 00:48, , 1F
double cPoint::XplusY() { return x + y; }
06/02 00:48, 1F
感謝大大!!!! ※ 編輯: AgentSkye56 (1.163.211.86), 06/02/2015 20:39:26
文章代碼(AID): #1LR8d5Lb (C_and_CPP)