精華區beta EE_DSnP 關於我們 聯絡資訊
※ 引述《moonjustin (快點放長假吧@@)》之銘言: 你的問題問的很好, 有些東西的確值得在這裡澄清一下... : 借標題請問一下 : char* rrr=new char[5]; : 就我認知上這行式子會在local memory宣告rrr這個char*變數 : 而rrr裡面存的內容是他指向heap memory的位置 沒錯, 觀念很正確! : 那為何cout<<rrr;並不會顯示出這個位置? 因為系統將 "operator << (ostream& os, const char* str)" 重新 define 成將 str 所指的字串印出來. 你可以做一個實驗 --- ====== class A { .... // whatever public: friend ostream& operator << (ostream& os, const A*); }; ostream& operator << (ostream& os, const A*) { .... // do something other than printing out the address } int main() { A* a = new A; cout << a << endl; } ====== You will see "cout << a << endl" does not print out the address of 'a'... : 另cout<<(size_t)rrr;意思是說把rrr的"內容"強制放到一個size_t的變數內容裡面嗎? 是的. : 另cout<<(size_t*)rrr;也是這個意思嗎? 是的. 只不過是 "強制放到一個 size_t* 的變數內容裡面" : 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.121.136.41
moonjustin:謝謝老師 但我還有問題 12/09 22:00