Static 함수와 Static 변수
등록자 : cpueblo (유광희), 2008-10-16
출처 : http://www.java2s.com/Code/Cpp/Language/Staticfunctionandstaticvariable.htm
소스
#include
using namespace std;
class MyClass
{
// Static 변수 선언
static int i;
public:
// Static 함수 선언
static void init(int x)
{
i = x;
}
void show()
{
cout << i;
}
};
// MyClass 안의 static 으로 된 i 변수를 선언
int MyClass::i;
int main()
{
// init static data before object creation
MyClass::init(30);
MyClass x;
x.show();
return 0;
}
결과
30
http://codesarang.com. mail to cpueblo cpueblo.com
|