有关问题关于类
问题关于类
#include <iostream>
using namespace std;
class sample
{int x;
public:
sample(int a)
{ x=a;
cout < < "constructing obj:x= " < <x < <endl;
}
};
void func(int n)
{static sample obj(n);
}
void main()
{func(1);
func(10);
}
为什么输出只是只有1行 不是两行??
------解决方案--------------------
自动忽略fun(10)
#include <iostream>
using namespace std;
class sample
{int x;
public:
sample(int a)
{ x=a;
cout < < "constructing obj:x= " < <x < <endl;
}
};
void func(int n)
{static sample obj(n);
}
void main()
{func(1);
func(10);
}
为什么输出只是只有1行 不是两行??
------解决方案--------------------
自动忽略fun(10)