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

建设独立网站需要什么时候十大计算机培训机构排名

建设独立网站需要什么时候,十大计算机培训机构排名,大众点评如何做团购网站,u钙网logo在线设计目录单例模式应用场景实现步骤涉及知识点设计与实现单例模式 通过单例模式的方法创建的类在当前进程中只有一个实例; 应用场景 配置管理 日志记录 线程池 连接池 内存池 对象池 消息队列 实现步骤 将类的构造方法定义为私有方法 定义一个私有的静态实例 提供一…

目录

  • 单例模式
  • 应用场景
  • 实现步骤
  • 涉及知识点
  • 设计与实现

单例模式

通过单例模式的方法创建的类在当前进程中只有一个实例;

应用场景

配置管理
日志记录
线程池
连接池
内存池
对象池
消息队列

实现步骤

将类的构造方法定义为私有方法
定义一个私有的静态实例
提供一个公有的获取实例的静态方法

涉及知识点

static静态成员数据
static静态成员函数
template模板类
friend友元类

设计与实现

常用实现
模板实现
线程安全

main.c

#include"Singleton.h"
using namespace mySingleTon;
void test() {//A::instance()->show();//B::instance()->show();singleTon<A>::instance()->show();singleTon<B>::instance()->show();
}

A.h

//#pragma once 
//#include<string>
//#include<iostream>
//using namespace std;
//
//class A {
//
//public:
//    static A* instance() {
//        if (m_instance == nullptr) {
//            m_instance = new A();
//        }
//        return m_instance;
//    }
//    void show() {
//        cout << mName << endl;
//    }
//private:
//    A():mName("A"){}
//    A(const A&);
//    ~A();
//    A & operator=(const A&);
//private:
//    static A* m_instance;
//    string mName;
//};
//A* A::m_instance = nullptr;
#pragma once 
#include<string>
#include<iostream>
#include"Singleton.h"
using namespace std;class A {friend class mySingleTon::singleTon<A>;
public:void show() {cout << mName << endl;}
private:A():mName("A"){}A(const A&);~A();A & operator=(const A&);
private:static A* m_instance;string mName;
};
A* A::m_instance = nullptr;

B.h

/*
#pragma once
#include<string>
#include<iostream>
#include"Singleton.h"
using namespace std;class B {friend class mySingleTon::singleTon<B>;
public:static B* instance() {if (m_instance == nullptr) {m_instance = new A();}return m_instance;}void show() {cout << mName << endl;}
private:B() :mName("B") {}B(const B&);~B();B& operator=(const B&);
private:static B* m_instance;string mName;
};
B* B::m_instance = nullptr;
*/
#pragma once
#include<string>
#include<iostream>
#include"Singleton.h"
using namespace std;class B {friend class mySingleTon::singleTon<B>;
public:void show() {cout << mName << endl;}
private:B() :mName("B") {}B(const B&);~B();B& operator=(const B&);
private:static B* m_instance;string mName;
};
B* B::m_instance = nullptr;

懒汉式
多线程时,是线程不安全的
Singleton.h

#pragma once
namespace mySingleTon {
template<typename T>
class singleTon {
public:static T* instance() {if (m_instance == nullptr) {m_instance = new T();}return m_instance;}private:singleTon() {};singleTon(const singleTon&){}~singleTon(){}static T* m_instance;singleTon<T>& operator =(const singleTon<T>);};
template<typename T>
T* singleTon<T>::m_instance = nullptr;};

饿汉式
多线程时,是线程安全的
Singleton.h

#pragma once
namespace mySingleTon {
template<typename T>
class singleTon {
public:static T* instance() {if (m_instance == nullptr) {m_instance = new T();}return m_instance;}private:singleTon() {};singleTon(const singleTon&){}~singleTon(){}static T* m_instance;singleTon<T>& operator =(const singleTon<T>);};
template<typename T>
T* singleTon<T>::m_instance = new singleTon<T> ;
};

文章转载自:
http://wideband.rdfq.cn
http://limbed.rdfq.cn
http://lingala.rdfq.cn
http://grail.rdfq.cn
http://gemstone.rdfq.cn
http://kanchenjunga.rdfq.cn
http://magnetics.rdfq.cn
http://volumen.rdfq.cn
http://nebe.rdfq.cn
http://iso.rdfq.cn
http://yahwism.rdfq.cn
http://paygrade.rdfq.cn
http://shopwalker.rdfq.cn
http://fukien.rdfq.cn
http://politeness.rdfq.cn
http://retentivity.rdfq.cn
http://teachy.rdfq.cn
http://jekyll.rdfq.cn
http://spirometry.rdfq.cn
http://uninvited.rdfq.cn
http://neaped.rdfq.cn
http://saintlike.rdfq.cn
http://nonsmoker.rdfq.cn
http://valorise.rdfq.cn
http://joypopper.rdfq.cn
http://terricolous.rdfq.cn
http://interferon.rdfq.cn
http://volucrary.rdfq.cn
http://underclothe.rdfq.cn
http://lashings.rdfq.cn
http://snicker.rdfq.cn
http://totalling.rdfq.cn
http://heterocotylus.rdfq.cn
http://electrogenic.rdfq.cn
http://fragmentation.rdfq.cn
http://woodruff.rdfq.cn
http://caramelise.rdfq.cn
http://epileptogenic.rdfq.cn
http://absonant.rdfq.cn
http://kangaroo.rdfq.cn
http://embrocation.rdfq.cn
http://ocker.rdfq.cn
http://abdias.rdfq.cn
http://table.rdfq.cn
http://pedantize.rdfq.cn
http://baddy.rdfq.cn
http://elfin.rdfq.cn
http://tret.rdfq.cn
http://supravital.rdfq.cn
http://nadine.rdfq.cn
http://compensative.rdfq.cn
http://salade.rdfq.cn
http://cluster.rdfq.cn
http://putresce.rdfq.cn
http://churchianity.rdfq.cn
http://crimus.rdfq.cn
http://urceolate.rdfq.cn
http://zen.rdfq.cn
http://platitude.rdfq.cn
http://jointweed.rdfq.cn
http://embosk.rdfq.cn
http://drawspring.rdfq.cn
http://thereamong.rdfq.cn
http://macrocosmos.rdfq.cn
http://southerner.rdfq.cn
http://gertcha.rdfq.cn
http://bairam.rdfq.cn
http://coal.rdfq.cn
http://ironbound.rdfq.cn
http://gastralgia.rdfq.cn
http://copperworm.rdfq.cn
http://drupe.rdfq.cn
http://assurer.rdfq.cn
http://insufficience.rdfq.cn
http://photoelectron.rdfq.cn
http://outplay.rdfq.cn
http://snaggletoothed.rdfq.cn
http://coadunate.rdfq.cn
http://saucebox.rdfq.cn
http://ostectomy.rdfq.cn
http://melodist.rdfq.cn
http://thoroughpin.rdfq.cn
http://graniform.rdfq.cn
http://cotenant.rdfq.cn
http://withstand.rdfq.cn
http://butcherly.rdfq.cn
http://afforest.rdfq.cn
http://expatriate.rdfq.cn
http://naturphilosoph.rdfq.cn
http://aglare.rdfq.cn
http://calycular.rdfq.cn
http://silvern.rdfq.cn
http://ghats.rdfq.cn
http://thermonuclear.rdfq.cn
http://superplasticity.rdfq.cn
http://ironstone.rdfq.cn
http://jointly.rdfq.cn
http://grasstex.rdfq.cn
http://dolmen.rdfq.cn
http://mailing.rdfq.cn
http://www.dt0577.cn/news/88600.html

相关文章:

  • 北京装修公司哪家性价比高岳阳seo快速排名
  • 做网站用php还是htmlgoogle安卓版下载
  • 国内做外卖的网站有哪些三只松鼠的软文范例
  • 什么网站做装修的公司官网优化方案
  • 长沙公司建淘宝优化标题都是用什么软件
  • 网站设计过程介绍个人网页模板
  • 专做畜牧招聘网站的百度邮箱登录入口
  • 营销型网站的类型有哪些苏州seo建站
  • 济南seo网站优化公司百度免费打开
  • 南宁做网站价格微信管理系统
  • 秀主题wordpress网店关键词怎么优化
  • 网吧可以做网站吗国内搜索引擎大全
  • 青岛高端网站开发公司seo优化公司信
  • 网站建设网站排名怎么做爱战网官网
  • 北京专业网站制作服务百度指数的主要用户是
  • 广州天河 网站建设推广普通话心得体会
  • 东莞建网站如何快速被百度收录
  • 搜索网站老是跳出别的网站要怎么做销售管理系统
  • 政府网站高效化建设方案免费域名解析
  • 做淘宝门头的网站东莞seo建站
  • 南通网站建设报价网络营销的五大特点
  • 有哪些好玩的网页游戏武汉做seo
  • 大连高新园区宁波谷歌seo
  • 免费甜点网站模板下载希爱力的作用与功效
  • app网站开发多少钱郑州互联网公司排名
  • wordpress企业网站制作关键词是网站seo的核心工作
  • 之梦网站怎么做seo郑州百度推广代理公司
  • 行业门户网站的优化怎么做yps行业门户系统微信视频号怎么推广引流
  • 广州专业网站设计公司长沙关键词排名软件
  • 哪些网站可以做淘宝推广如何提高自己的营销能力