c++ 单例存值
2021-08-31 本文已影响0人
刃之剑
#include <stdio.h>
#include <bio.h>
#include "string.h"
#include "common/json.h"
#ifndef _SINGLETON_H_
#define _SINGLETON_H_
#include <iostream>
class singleton //实现单例模式的类
{
private:
singleton() {} //私有的构造函数
public:
BIO *bioData;
string m_cn;
EVP_PKEY *signEvpPkey;
void setsignData(BIO *bioKey){
bioData = bioKey;
}
BIO* getsignData(){
return bioData;
}
static singleton* GetInstance()
{
static singleton Instance;
return &Instance;
}
};
#endif
场景需要使用单例存储数据从OC传值到C++,C++读取使用.将数据加载到内存,而不是从文件中读取(安全性)
赋值
singleton *model = singleton::GetInstance();
model->bioData=bioPKey;
使用
singleton * model = singleton::GetInstance();
bioPKey = model->bioData;
evpPkey = model->signEvpPkey;