In this case, there should be only one or zero instances of the static variable. It depends whether f() has been called or not.
void f()
{
static int a;
}
But how many instances of the static variable are there if f() is a method?
class A
{
void f()
{
static int a;
}
};
Same as for the function: 0 or 1. It is very easy to check too:
Output:
However, if you derieve from
class Aand make the function virtual like this:then the
avariable will be different for the base and for each derived class (because the functions are different too).