DoubleLi

qq: 517712484 wx: ldbgliet

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

C++函数模版与类模版。

复制代码
template <class T>

void SwapFunction(T &first, T &second){

}//函数模版

template <class T>//类模版

class CTemplate{

public:

    void SWap(T &first, T &second){

    }

};

 

#include <iostream>
class Single{
public:
    static Single*  ShareInstance();
    static void ReleaseInstance();
     template<class Tex>//要成员函数实现模版用法,而类不是模版类。需要写成这个格式
    void SwapEx(Tex &obj1, Tex &obj2){
    }
private:
    Single();
    ~Single();
    Single(const Single &other);
    Single& operator=(const Single &other);
    
private:
    static Single *m_pObj;
};

Single* Single::m_pObj = NULL;

Single* Single::ShareInstance(){
    if (NULL == m_pObj) {
        Single obj;
        m_pObj = new Single();
    }
    return m_pObj;
}

void Single::ReleaseInstance(){
    if (m_pObj) {
        delete m_pObj;
        m_pObj = NULL;
    }
}

Single::Single(){
    
}
Single::~Single(){
    
}
posted on 2014-09-01 15:37  DoubleLi  阅读(9734)  评论(0编辑  收藏  举报