这段代码存在空指针引用的问题。在主函数中,指针ptr被声明,但没有分配内存给它,因此它是一个空指针。在调用ptr的成员函数之前,需要先为ptr分配内存,例如使用new关键字来实例化一个Dog对象,并将其赋值给ptr。

#include iostream#include stringhusing namespace std;class Dogpublic	void hello 		cout hello endl;		void show 		cout show m_value endl;	private	int m_value;;int main		Dog ptr = nullptr;	Dog ptr;

原文地址: http://www.cveoy.top/t/topic/iJWB 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录