CodeSarang.Com
Home | All categories Join | Login | 검색   

 

Static 맴버 값 예제

등록자 : cpueblo (유광희), 2008-10-16
글수정 | 글삭제


예제 소스 출처 : http://www.java2s.com/Code/Cpp/Language/Astaticmembervariableexample.htm

소스

#include <iostream> using namespace std; class myclass { static int i; public: void setInt(int n) { i = n; } int getInt() { return i; } }; int myclass::i; // i 를 선언. i 는 private 로 선언되어 있음 int main() { myclass object1, object2; object1.setInt(10); cout << "object1.i: " << object1.getInt() << '\n'; // 10 을 출력 cout << "object2.i: " << object2.getInt() << '\n'; // 똑같이 10을 출력. Static return 0; }

결과

object1.i: 10 object2.i: 10



글수정 | 글삭제
http://codesarang.com. mail to cpueblocpueblo.com