如何设计一个模板类

1. 示例

 1 #include <vector>
 2 
 3 using std::vector;
 4 // -------------------------------------------------------------------------------
 5 template <class T>
 6 class TVector {
 7 private:
 8     vector<T> m_stackData;
 9     vector<T> m_stackMin;
10 public:
11     void push(T item);
12     T     pop(void);
13     T      getMin(void);    
14     TVector();
15     ~TVector();        
16 };
17 // ------------------------------------------------------------
18 template<class T>
19 TVector<T>::TVector(void){
20     m_stackData.clear();
21     m_stackMin.clear();
22 }
23 
24 template<class T>
25 TVector<T>::~TVector<T>(){    
26 }
27 // ------------------------------------------------------------

2. 类声明

1 template <class type>
2 class Tname{
3 private:
4     type a;
5 public:
6 }

 3. 类定义

1 template<class type>
2 Tname<type>::Tname(){
3 }

 

posted @ 2016-06-19 17:09  helo_blog  阅读(243)  评论(0编辑  收藏  举报