D
D
DmitryProsh2016-08-29 00:33:49
C++ / C#
DmitryProsh, 2016-08-29 00:33:49

C++ Why is static variable not created?

Such an error:
error: C2065: cout
:

class counter
{
public:
    static int count;
    void setcount(int i)
    {
        counter::count = i;
    }
    void showcount ()
    {
//На эту строку ошибка C2065: cout: ­Ґ®Ўкпў«Ґ­­л© Ё¤Ґ­вЁдЁЄ в®а
        cout << counter::count << " ";
    }
};

int counter::count; // определение count

int main()
{
    counter a, b;
    a.showcount (); // выводит 0
    b.showcount (); // выводит 0
    a.setcount (10); // установка статического count в 10
    a.showcount (); // выводит 10
    b.showcount (); // также выводит 10
return 0;
}

I do according to the manual, but it does not work, help!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question