标签:span sed tail isp 技术 ace 控制台应用程序 eve str
参考http://blog.csdn.net/calmreason/article/details/51029285
定义一系列相同的算法 根据不同需求选择不同的算法策略
代码
// 004.cpp: 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <memory> #include <iostream> using namespace std; class Strategy { public: virtual void doAlgorithm(void) = 0; virtual ~Strategy(){} protected: }; class StrategyA :public Strategy { void doAlgorithm(void) { std::cout << __FUNCTION__ << std::endl; } }; class StrategyB :public Strategy { void doAlgorithm(void) { std::cout << __FUNCTION__ << std::endl; } }; class UseStrategy { public: UseStrategy(std::shared_ptr<Strategy> ps) :ps_(ps) {} void useAlgorithm(void) { std::shared_ptr<Strategy> ps = this->ps_.lock(); ps->doAlgorithm(); } private: std::weak_ptr<Strategy> ps_; }; int main() { std::shared_ptr<Strategy> ps = std::make_shared<StrategyA>(); UseStrategy user(ps); user.useAlgorithm(); ps = std::make_shared<StrategyB>(); UseStrategy user1(ps); user1.useAlgorithm(); return 0; }
标签:span sed tail isp 技术 ace 控制台应用程序 eve str
原文地址:http://www.cnblogs.com/itdef/p/7456887.html