#include<iostream>
using namespace std;

class parent {
public:
	virtual void fun() {
		cout << "我是父类虚函数" << endl;
	}
	void fun2() {
		cout << "我是父类普通函数" << endl;
	}
};
class child :public parent {
public:
	virtual void fun() {
		cout << "我是子类虚函数" << endl;
	}
	void fun2() {
		cout << "我是子类普通函数" << endl;
	}
};

int main() {
	parent* ptr = new child();
	ptr->fun();//调用子类函数
	ptr->fun2();//调用父类函数
	system("pause");
	return 0;
}

  

相关文章:

  • 2022-12-23
  • 2021-06-04
  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-27
  • 2021-06-19
  • 2021-03-31
  • 2021-10-08
  • 2021-11-23
  • 2021-05-27
相关资源
相似解决方案