(Owed by: 春夜喜雨 http://blog.csdn.net/chunyexiyu)
类的包装尝试:
把检查与检查非包装出来,组合满足业务需求就比较方便了。
1. 检查某容器包含0
2. 不满足时
...
// 检查容器中元素是否满足某种条件template <typename T>bool Check(T& container){ if (container.IsSatify()) { return true; } return false;};// 基类:提供检查接口class CCheckPRoc{public: CCheckProc():m_pParent(nullptr){}; CCheckProc(CCheckProc& proc):m_pParent(&proc){}; virtual bool IsSatify() = 0;protected: CIndexProc* m_pParent;};// 继承类:提供检查包含0的接口template <typename T>class CIncludeZero : public CCheckProc{public: CIncludeZero(T& container):m_pContainer(&container) {}; virtual bool IsSatify() { return m_pContainer->contains(0); };private: T* m_pContainer;};// 继承类:提供检查非的操作class CNotIn : public CCheckProc{public: CNotIn(CCheckProc& proc):CCheckProc(proc){} virtual bool IsSatify(int nIndex) { return !m_pParent->IsSatify(nIndex); };};// 实例化函数,提供给外部使用bool IncludeZero(QList<int>& indexs ){ return Check(n, CIncludeZero<QList<int>>(indexs));}bool NotIncludedZero(QList<int>& indexs){ return Check(n, CNotIn(CIncludeZero<QList<int>>(indexs)));}(Owed by: 春夜喜雨 http://blog.csdn.net/chunyexiyu)
新闻热点
疑难解答