mirror of
https://github.com/Light-City/CPlusPlusThings.git
synced 2026-02-06 12:04:22 +08:00
support bazel complie this project and format code.
This commit is contained in:
@@ -2,27 +2,23 @@
|
||||
// Created by light on 20-2-6.
|
||||
//
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
class singleton {
|
||||
private:
|
||||
singleton(); //私有构造函数,不允许使用者自己生成对象
|
||||
singleton(const singleton &other);
|
||||
singleton(); //私有构造函数,不允许使用者自己生成对象
|
||||
singleton(const singleton &other);
|
||||
|
||||
//要写成静态方法的原因:类成员函数隐含传递this指针(第一个参数)
|
||||
static void init() {
|
||||
p = new singleton();
|
||||
}
|
||||
//要写成静态方法的原因:类成员函数隐含传递this指针(第一个参数)
|
||||
static void init() { p = new singleton(); }
|
||||
|
||||
static pthread_once_t ponce_;
|
||||
static singleton *p; //静态成员变量
|
||||
static pthread_once_t ponce_;
|
||||
static singleton *p; //静态成员变量
|
||||
public:
|
||||
singleton *instance() {
|
||||
// init函数只会执行一次
|
||||
pthread_once(&ponce_, &singleton::init);
|
||||
return p;
|
||||
}
|
||||
singleton *instance() {
|
||||
// init函数只会执行一次
|
||||
pthread_once(&ponce_, &singleton::init);
|
||||
return p;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user