首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

求下面程序的答案及原因,该如何处理

2012-03-15 
求下面程序的答案及原因#includeiostream.hclass Sample{int xpublic:Sample(int a){xacoutconstr

求下面程序的答案及原因
#include<iostream.h>
class Sample 
{
int x;
public:
Sample(int a)
{
x=a;
cout<<"constructing object:x="<<x<<endl;
}

};
void func(int n)
{
static Sample s(n);
}
void main()
{ func(10);
func(1);

}

[解决办法]
static变量只会被初始化一次……

热点排行