클래스변수/함수
C언어의 static
static 멤버변수 (클래스 변수)
#include <iostream>
using namespace std;
class Simple {
static int objCount;
public :
Simple() {
objCount++;
cout << objCount << "번째 객체 : 생성" << endl;
}
Simple(const Simple& copy) {
objCount++;
cout << objCount << "번째 객체 : 복사생성" << endl;
}
};
// static 변수의 초기화
int Simple::objCount = 0;
int main() {
Simple obj1;
Simple obj2 = obj1;
return 0;
}static 변수의 다른 접근 방법
static 멤버함수
const static 멤버변수
Last updated