2014-04-23 3 views
0

일부 작업이 있습니다. 많은 .cpp 파일이 있으므로 각 변수의 전역 변수 선언을 모두 찾아야합니다. 그래서 예를 들어,이 코드 부분이 있습니다 :C++ - 전역 변수 범위

class word { 
public: 
    word(string code0, string text0, int weight0) : code(code0), text(text0), 
    weight(weight0), index(word::num) {}; 
    friend bool operator<(word w1, word w2); 
    friend ostream &operator<<(ostream &stream, word w); 
    friend bool wordWithCode::operator()(const word &w); 
    static bool convertChars(char *inp, char *out); 
    inline bool checkCode(char *check) { return !strcmp(code.c_str(),check); }; 
    inline const char* getText() { return text.c_str(); }; 
    inline void useIt(set<word>::iterator &i) { 
     cout << this->text; 
     if (code[0]!='1') { 
      word::num++; 
      word::words.insert(word(this->code,this->text,this->weight+1)); 
      word::words.erase(i); 
     } 
     return; 
    }; 
    static set<word> words; 
    string code; 
    string text; 
    int weight; 
    static int num; 
private: 
    int index; 
}; 

int word::num = 0; 
set<word> word::words; 

int main(){ 
    ... 
    return 0; 
} 

내 질문 : 정적 변수 word :: num 및 word :: words는 전역 변수입니까? 그리고 그들의 이름 (정확하게 "num"또는 "word :: num")을 정확하게 식별하는 방법은 무엇입니까?

답변

1

예, 이들은 단일 전역 변수이며 단어 기능 외에서는 word::numword::words으로 참조합니다. 내부 단어 기능은 numwords

과 같이 참조 할 수 있습니다.