C++ (Qt)template <class T, int minCount, int maxCount>class LimitList{public: bool add( const T &item ) { if( m_list.size() >= maxCount ) return false; m_list.append( item ); return true; } bool remove(...) { } private: QList<T> m_list;};
template <class T> class LimitList { public: LimitList(); bool add( const T &item ); private: int maxCount; QList<T> m_list; };
template<class T>LimitList< T>::LimitList(){ maxCount = 10;}template <class T>bool LimitList< T>::add( const T &item ){ if( m_list.size() >= maxCount ) return false; m_list.append( item ); return true;}