您当前的位置: 首页 >  c++

qianbo_insist

暂无认证

  • 0浏览

    0关注

    399博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

c++友元模板单例模式

qianbo_insist 发布时间:2021-06-30 20:22:59 ,浏览量:0

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

关注
打赏
1663161521
查看更多评论
立即登录/注册

微信扫码登录

0.0360s