[問題] 透過 null pointer 呼叫 member function

看板C_and_CPP作者 (浪無定所)時間11年前 (2013/02/25 17:48), 編輯推噓2(202)
留言4則, 4人參與, 最新討論串1/1
不好意思,謝謝。 開發平台(Platform): (Ex: VC++, GCC, Linux, ...) VC++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 只是一個Pointer卻可以執行Funtion,debug過程也確定其值為null。不太了解 餵入的資料(Input):預期的正確結果(Expected Output): error 錯誤結果(Wrong Output): 螢幕印出 : I AM HERE 程式碼(Code):(請善用置底文網頁, 記得排版) class test { public: void print() { cout << "I AM HERE" << endl; } }; int main() { test* p1 = NULL; p1->print(); } 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.160.170.17 ※ 編輯: crazycat2 來自: 118.160.170.17 (02/25 17:51)

02/25 17:58, , 1F
看這篇 #1BhSQmEi
02/25 17:58, 1F

02/25 17:59, , 2F
#1GBczBqy 這篇也可以看
02/25 17:59, 2F

02/25 18:00, , 3F
太感謝!!! 謝謝你們
02/25 18:00, 3F

02/26 17:10, , 4F
原來這樣可以過...
02/26 17:10, 4F
文章代碼(AID): #1HApE7HS (C_and_CPP)