Re: [問題] 程式看不懂 請幫幫我><
※ 引述《abcxxxx (撐過就是神)》之銘言:
: 開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
: dev c++
: 程式碼(Code):(請善用置底文網頁, 記得排版)
: .
: .
: .
: int main()
: {
: Time test;
: test.print_time(test); //呼叫print_time函數
: }
如果 print_time 是 non-static member function, 那麼要印出資訊
在你 test.print_time 下去的時候就可以決定好了(透過this存取),
不必為了印自己的資訊還要再多個參數來傳.
: 問題
: 將函數print_time指定給宣告此函數的類別
: 其中掛號裡面的內容我不懂為什麼還要多加上const 謝謝各位
const Time & t ←─→ Time const & t
兩者等價, 但我 prefer 右邊的寫法, 這樣從右至左解讀會比較通
順:
t is a reference which refers to a const Time object
reference 參考到傳進來的引數, 加上 const 的目的當然為了避
免你修改掉引數的值, 以下是印出座標點的程式:
struct Point {
int x, y;
Point( int x, int y ) {
this->x = x;
this->y = y;
}
void print() {
++x;
cout << "(" << x << "," << y << ")" << endl;
}
};
Point p( 3, 5 );
p.print(); // 印出 ?
抓 Bug 哪種寫法好抓? 寶傑你說呢?
別人告訴你然後死背是沒用的! 寫程式要靠多練習才會有fu, 前面
的程式碼讓我覺得你真的需要好好重練一下...
--
★ ★ ★ ★
★ ★ ★ ███ ███ █ █▌█ ██◣ ███ ▋▋█ ★ ★ ★
█▂█ █▃█ █ ███ █▆█ █▄█ ███
★ ★ █ ◣ █ █ █ ▋██ █▆◤ ███ ███ ★ ★
Kim Jae Kyung Koh Woo Ri Cho Hyun Young Kim Ji Sook
φwindyhorse No Eul Oh Seung A Jung Yoon Hye
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.44.81.120
※ 編輯: loveme00835 來自: 114.44.81.120 (01/22 21:20)
→
01/23 14:45, , 1F
01/23 14:45, 1F
推
01/23 15:00, , 2F
01/23 15:00, 2F
推
01/26 14:38, , 3F
01/26 14:38, 3F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):