1、定义一个单例的模板类,以便于其他类可以继承
template struct singleton
{
static T& Instance();
};
template
T& singleton::Instance()
{
static T t_;
return t_;
}
2、实现
class util_tool :public singleton
{
private:
string m_strExePath;
public:
util_tool(void){}
~util_tool(void) {}
public:
string getpath()
{
return "hello test";
}
};
把类从模板类上继承,这里的构造函数只能是公用的
3、调用int main() { cout
关注
打赏