[問題] 物件呼叫問題

看板C_and_CPP (C/C++)作者 (yshihyu)時間13年前 (2012/09/14 21:38), 編輯推噓1(102)
留言3則, 2人參與, 最新討論串1/1
#include <iostream> using namespace std; class A { public: void test(); }; void A::test() { cout << "Hello" << endl; } int main() { A *a; a = NULL; a->test(); } 為什麼是 a 是 NULL 還可以呼叫到 class A 中的 test() 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.204.96.39

09/14 21:42, , 1F
因為型別沒變
09/14 21:42, 1F

09/14 22:06, , 2F
a->test() => class_A_method_test(A* this = a)
09/14 22:06, 2F

09/14 22:06, , 3F
你沒用到this或其他成員就不會有問題
09/14 22:06, 3F
文章代碼(AID): #1GKpCzZe (C_and_CPP)
文章代碼(AID): #1GKpCzZe (C_and_CPP)