当前位置: 首页 > news >正文

国外做网站侵权/财经新闻最新消息

国外做网站侵权,财经新闻最新消息,网站建设需要怎么做,建筑人才网官网96877单例模式 该示例代码采用C11标准&#xff0c;解决以下问题&#xff1a; 通过类模板函数实现不同类型单例&#xff1b;单例类构造函数支持不同的个数&#xff1b;消除代码重复 示例代码 .h文件如下&#xff1a; //C11Singleton.h文件 #pragma oncetemplate <typename T&…

单例模式

该示例代码采用C11标准,解决以下问题:

  1. 通过类模板函数实现不同类型单例;
  2. 单例类构造函数支持不同的个数;
  3. 消除代码重复

示例代码

.h文件如下:

//C++11Singleton.h文件
#pragma oncetemplate <typename T>
class Singleton
{
public:template<typename... Args>static T* Instance(Args&&... args){if (m_pInstance == nullptr){m_pInstance = new T(std::forward<Args>(args)...);}return m_pInstance;}static T* GetInstance(){if (m_pInstance == nullptr){throw std::logic_error("the instance is not init,please initialize the instance first");}return m_pInstance;}static void DestorInstance(){delete m_pInstance;m_pInstance = nullptr;}private:Singleton();virtual ~Singleton();Singleton(const Singleton&);Singleton& operator = (const Singleton&);
private:static T* m_pInstance;
};

.cpp文件如下:

#include <iostream>
#include "C++11Singleton.h"
using namespace std;template <class T> T* Singleton<T>::m_pInstance = nullptr;struct A
{A(const string&) { cout << "lvalue" << endl; };A(string&& x) { cout << "rvalue" << endl; };
};struct B
{B(const string&) { cout << "lvalue" << endl; };B(string&& x) { cout << "rvalue" << endl; };
};struct C
{C(int x, double y) {};void Fun() { cout << "test" << endl; };
};int main()
{string str = "bb";Singleton<A>::Instance(str);Singleton<B>::Instance(std::move(str));Singleton<C>::Instance(1,3.14);Singleton<C>::GetInstance()->Fun();Singleton<A>::DestorInstance();Singleton<B>::DestorInstance();Singleton<C>::DestorInstance();cin.get();return 0;
}

输出结果如下:
在这里插入图片描述
以上只是个示例,该单例非模式还不支持多线程调用。

http://www.whsansanxincailiao.cn/news/32020482.html

相关文章:

  • 北京市建设部网站/黄冈网站推广
  • 跨境电商综合服务平台有哪些/seog
  • 免费推广网站哪家好/自己建网站要花多少钱
  • wordpress 百度知道主题/石家庄高级seo经理
  • 网站推广活动/十大跨界营销案例
  • 汉阳网站推广/潮州网站建设
  • 大连自动seo/seo监控
  • 创建网站的软件什么梦/太原百度搜索排名优化
  • 网站开发自学网/搜索引擎排名营销
  • 南昌网站搭建服务/怎样优化网站排名靠前
  • 做怎么样的自己的网站/四川聚顺成网络科技有限公司
  • ubuntu做的网站架构/seo学徒是做什么
  • 凡科建站相关链接/微博关键词排名优化
  • 老阿姨哔哩哔哩b站肉片入口直播/技能培训学校
  • 深圳网站制作哪家好薇/seo关键词排名公司
  • 免费包装设计网站/sem是什么岗位
  • 不会写代码怎么做网站/seo入门
  • 青岛网站建设公司/百度seo推广软件
  • 电子商务网站建设的工具/电商运营公司排名
  • 服装公司网站结构/淄博新闻头条最新消息
  • 网站建设数据安全分析/人工智能培训
  • 网站注册备案之后怎么做网站/app软件推广平台
  • 外贸建站用的服务器/公司网站建设哪个好
  • 网站建设岗位能力/站长统计app进入网址新版小猪
  • 建设工程检测预约网站/网站是怎么做出来的
  • 什么是网站主题优化/aso优化渠道
  • wordpress 不同分类目录调用不同模板的方法/seo神器
  • 做网站卖掉/百度官方网址
  • 推广普通话活动总结/seo优化怎么做
  • 厦门建设网站公司/百度旗下所有app列表