如何将INT参数放入C 中的Sigleton构造器中
How to put int parameter into Sigleton constructor in C++
#include "Generator.h"
#include "Proxy.h"
Proxy::Proxy(int inputbits):Generator(inputbits)
{
}
Proxy::~Proxy()
{
}
Generator * Proxy::operator ->()
{
if(counter<=10)
return rPointer;
else
return 0;
}
//Proxy* Proxy::instance = 0;
Proxy* Proxy::getInstance()
{
static Proxy* instance;
return instance;
}
。
#ifndef PROXY_H
#define PROXY_H
#include "Generator.h"
class Proxy: private Generator
{
public:
~Proxy();
static Proxy* getInstance();
Generator * operator ->();
private:
Proxy();
Proxy(int);
int bits;
int counter;
Generator * rPointer;
};
#endif // GENERATORPROXY_H
这些是我的单身人士的代码,我想做的是我想在Main函数中作为Proxy::Proxy(int inputbits):Generator(inputbits)
的代理对象将某些论点传递给构造函数,我将使用GetInstance函数,但是它不起作用。如果您有任何想法,请启发我。谢谢,我期望能够做的就是例如,在主要功能中,代理PX(3(;&lt; - 我知道这是不起作用的,但是我想以任何方式使用类似的东西。
您可以在另一个功能的帮助下完成,该功能在其呼叫上提供所需的位。
int get_bits() {
return 3;
}
Proxy *Proxy::getInstance() {
static Proxy* instance = new Proxy(get_bits());
return instance;
}
或在单个Proxy
默认构造函数中进行(更好(
Proxy::Proxy():Generator(get_bits()) {
}
相关文章:
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- .cpp和.h文件中的模板专用化声明
- 反向给定链表中的K节点
- 正在查找文档以获得PS4平台的C++中的设备信息
- enum是C++中的宏变量还是整数变量
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 将字符串存储在c++中的稳定内存中
- 文本文件中的单词链表
- 递归函数计算序列中的平方和(并输出过程)
- 如何从C++中的依赖类型中获得它所依赖的类型
- C++中的"inline"关键字
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 用C++中的一个变量定义一个常量
- vector.resize()中的分配错误
- 使用指针从C++中的数组中获取最大值
- arr[-1]在c++中的奇怪行为
- 具有奇怪重复模板模式的派生类中的成员变量已损坏
- 将值指定给向量(2D)的向量中的某个位置
- 如何将INT参数放入C 中的Sigleton构造器中