未名
5毛党党员
全部博文(17)
2011年(1)
2009年(16)
anank
7717060
flw
HonestQi
scutan
cugb_cat
浅尝寂寞
gong_yue
分类: C/C++
2009-02-24 16:38:49
#include <string> #include <iostream> using namespace std; class AbstractClass { public: virtual void PrimitiveOperation1() = 0; virtual void PrimitiveOperation2() = 0; void TemplateMethiod() { PrimitiveOperation1(); PrimitiveOperation2(); cout<<" "<<endl; } }; class ComcreateClassA : public AbstractClass { public: virtual void PrimitiveOperation1() { cout<<"具体类A方法1实现"<<endl; } virtual void PrimitiveOperation2() { cout<<"具体类A方法2实现"<<endl; } }; class ComcreateClassB : public AbstractClass { public: virtual void PrimitiveOperation1() { cout<<"具体类B方法1实现"<<endl; } virtual void PrimitiveOperation2() { cout<<"具体类B方法2实现"<<endl; } }; int main(void) { AbstractClass* c; c = (AbstractClass*)new ComcreateClassA(); c->TemplateMethiod(); c = (AbstractClass*)new ComcreateClassB(); c->TemplateMethiod(); };
上一篇:没有了
下一篇:装饰模式(Decorator)_c++
登录 注册