#include <iostream>
using namespace std;
class Shape {//抽象类
public:
	void begin() { cout << "绘图开始" << endl; }
	void end() { cout << "绘图结束" << endl; }
	virtual void draw() = 0;//纯虚函数
	void paint() {//模板方法
		begin();
		draw();
		end();
	}
};

class Circle :public Shape {
public:
	void draw() {
		cout << "Draw a cirle" << endl;
	}
};

int main(int argc, char argv[]) {
	Shape *pObj = new Circle();
	pObj->paint();
	delete pObj;
	system("pause");
	return EXIT_SUCCESS;
}

C++之——模板方法

相关文章:

  • 2021-12-27
  • 2022-12-23
  • 2021-10-17
  • 2021-10-24
  • 2021-08-24
  • 2021-04-03
猜你喜欢
  • 2022-12-23
  • 2021-09-27
  • 2022-12-23
  • 2021-10-08
  • 2021-06-29
  • 2022-12-23
  • 2020-07-14
相关资源
相似解决方案