user3557239
user3557239

Reputation: 1

C++ - global variable scope

I have some task: There are a lot of .cpp files, so I must find all the declarations of global variables in each of them. So I have, for example, this part of code:

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;
}

So my question: Is the static variables word::num and word::words are global? And how to correctly identify their names(just "num" or "word::num")?

Upvotes: 0

Views: 76

Answers (1)

cppguy
cppguy

Reputation: 3713

Yes, they're single global variables and you reference them outside of word's functions as word::num and word::words. Inside word's functions you can reference them just as num and words

Upvotes: 1

Related Questions