在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
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(){ }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论