空指针访问成员函数

unadlib

关注

阅读 86

2022-02-23

class Phone {
public:
	Phone(){
	}

	Phone(int num):phoneNum(num) 
	{
	}

	void shout() {
		cout << "ccc" << endl;
	}

	void shout2() {
		if (this == NULL) {
			return;
		}
		cout << this->phoneNum << endl;
	}

    int phoneNum;
};



void test() {
	Phone* p = NULL;//空指针访问成员函数
	p->shout();
	p->shout2();
}

int main() {
	test();
}

相关推荐

精彩评论(0)

0 0 举报