zoukankan      html  css  js  c++  java
  • c++ 类模版、成员函数模版、函数模版 用法

    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(){
        
    }
  • 相关阅读:
    ruby学习系列(1)
    学习调用WCF服务的各种方法
    Web Service简介
    ajax编程
    ReportView控件的使用
    .NET中26个优化性能方法
    图书管理前端页面
    图书管理后端接口
    Vue组件
    axios登录前端
  • 原文地址:https://www.cnblogs.com/MrYuan/p/4736588.html
Copyright © 2011-2022 走看看