In the following example (taken from here) we have a private static variable x and then we change its name outside of the class. What confuses me is why is it allowed to change a private variable outside of the class? What is then the reason to declare it a private
.
// static_member_functions.cpp
#include <stdio.h>
class StaticTest
{
private:
static int x;
public:
static int count()
{
return x;
}
};
int StaticTest::x = 9;
int main()
{
printf_s("%d\n", StaticTest::count());
}