返回信息流问,为什么get_instance函数中的a = new A(h);得不到执行,换句话说。在我必须传递一个参数h才能去指定他的第一次初始化状态时,应该怎么做。
#include<iostream>
using namespace std;
class A
{
private:
int sem;
static A* a;
public:
static A* get_instance(int& h)
{
A* a;
if(a == NULL)
{
cout<<"i m in get_instance"<<endl;
a = new A(h);
} else
return a;
return a;
}
private:
A(int& h):sem(h)
{
std::cout<<"Constructor."<<std::endl;
}
/*
//copy constructor
A(const A& a)
{
std::cout<<"in copy constructor"<<std::endl;
}*/
};
class B
{
private:
static int mb;
public:
static A* a_instance;
};
int B::mb;
A* B::a_instance = A::get_instance(mb);
int main()
{
}
这是一条镜像帖。来源:北邮人论坛 / cpp / #24104同步于 2009/5/22
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
[求助]下面这个实例为什么没有初始化
vanish
2009/5/22镜像同步1 回复
订阅后,新回复会通过你的通知中心匿名送达。
1 条回复