c++ 類模版、成員函數模版、函數模版 用法
睿豐德科技 專注RFID識別技術和條碼識別技術與管理軟件的集成項目。質量追溯系統、MES系統、金蝶與條碼系統對接、用友與條碼系統對接
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(){
}
RFID管理系統集成商 RFID中間件 條碼系統中間層 物聯網軟件集成