[問題] C++ class this問題

看板C_and_CPP (C/C++)作者 (沒有暱稱)時間11年前 (2014/11/22 02:14), 11年前編輯推噓4(406)
留言10則, 6人參與, 最新討論串1/1
書上寫 class time{ private: int hour; public: void set(int h){this->hour=h;} void print(){cout<<this->hour;} }; 想請教一下this指標 上述兩行的this是隱藏參數 可是沒有傳this進來 在裡面卻有this 感覺很奇怪 還是說其實有 像void print(time *this){cout<<this->hour;} 只是也隱藏起來了? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.160.29.52 ※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1416593696.A.0F6.html ※ 編輯: anoymouse (118.160.29.52), 11/22/2014 02:15:09

11/22 02:43, , 1F
member function都會隱晦地傳進this pointer
11/22 02:43, 1F

11/22 02:44, , 2F
更正,non-static member functions
11/22 02:44, 2F

11/22 02:44, , 3F
所以是像我最後一行這樣傳進嗎?
11/22 02:44, 3F

11/22 03:34, , 4F
是的
11/22 03:34, 4F

11/22 11:13, , 5F
型態是 T * const
11/22 11:13, 5F

11/22 12:01, , 6F
請問T是什麼?
11/22 12:01, 6F

11/22 13:47, , 7F
template吧,想表達的意思大概就該class型別的pointer
11/22 13:47, 7F

11/22 14:56, , 8F
嗯, 以及這個 this 指標不能被改指 (它是 const pointer)
11/22 14:56, 8F

11/22 16:13, , 9F
好 我再看看有問題再問 謝謝各位!
11/22 16:13, 9F

11/26 04:09, , 10F
this是keyword 意思就是「自己這個實體」
11/26 04:09, 10F
文章代碼(AID): #1KRu4W3s (C_and_CPP)
文章代碼(AID): #1KRu4W3s (C_and_CPP)