Same as function: 0 or 1. It is also very easy to check:
class A { public: void f() { static int a = 0; ++a; cout << a << endl; } }; int main() { A a; af(); af(); A b; bf(); }
Conclusion:
1 2 3
However, if you obsess with class A
and make the function virtual, like this:
class A { public: virtual void f() { static int a = 0; ++a; cout << a << endl; } }; class B:public A { public: void f() { static int a = 0; ++a; cout << a << endl; } };
then the variable a
will be different for the base and for each derived class (because the functions are also different).
source share