求下面程序的答案及原因
#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变量只会被初始化一次……