이런 거 말씀인가요?
#include <iostream>
using namespace std;
static int ppp::value = 10;
class ppp{
int value;
...
티윅 님이 쓰신 글 :
: 밑의 프로그램에서 클래스 ppp의 value라는 녀석을 static int value;로 즉 static를 붙여서 사용하려면 어떻게 프로그램을 수정해야 할까요 도와주세요!
:
: #include <iostream>
: using namespace std;
:
: class ppp{
: int value;
: public:
: ppp(int n) {this -> value = n; }
: void inc() {++this -> value; }
: void dec() {--this -> value; }
: int val() { return this -> value; }
: };
:
: int main(void)
: {
: ppp cnt1(16), cnt2 (6);
:
: cnt1.inc();
: cout << "cnt1 :" << cnt1.val() << endl;
:
: cnt2.dec();
: cout << "cnt2 :" << cnt2.val() << endl;
: return 0;
: }
:
|