0
点赞
收藏
分享

微信扫一扫

空指针访问成员函数

unadlib 2022-02-23 阅读 83
c++指针
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 条评论