码迷,mamicode.com
首页 > 编程语言 > 详细

Template模式C++实现

时间:2020-05-16 18:27:20      阅读:57      评论:0      收藏:0      [点我收藏+]

标签:str   stream   namespace   star   lan   实现   space   ios   cte   

技术图片

#include <iostream>
using namespace std;

class AbstractClass {
public:
    void TemplateMethod() {
        cout << "PrimitiveOperation1() Start" << endl;
        PrimitiveOperation1();
        cout << "PrimitiveOperation1() End" << endl;

        cout << "PrimitiveOperation2() Start" << endl;
        PrimitiveOperation2();
        cout << "PrimitiveOperation2() End" << endl;
    }
protected:
    virtual void PrimitiveOperation1() {
        cout << "AbstractClass Operation1" << endl;
    }
    virtual void PrimitiveOperation2() {
        cout << "AbstractClass Operation2" << endl;
    }
};

class ConcreteClass : public AbstractClass {
protected:
    virtual void PrimitiveOperation1() {
        cout << "ConcreteClass Operation1" << endl;
    }
    virtual void PrimitiveOperation2() {
        cout << "ConcreteClass Operation2" << endl;
    }
};

int main() {
    AbstractClass * pAbstractClass = new ConcreteClass();
    pAbstractClass->TemplateMethod();
    if (pAbstractClass) delete pAbstractClass;
    return 0;
}

Template模式C++实现

标签:str   stream   namespace   star   lan   实现   space   ios   cte   

原文地址:https://www.cnblogs.com/wstong/p/12900848.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!