当静态成员被继承时,它们对于整个层次结构还是整个类都是静态的,即:
class SomeClass
{
public:
SomeClass(){total++;}
static int total;
};
class SomeDerivedClass: public SomeClass
{
public:
SomeDerivedClass(){total++;}
};
int main()
{
SomeClass A;
SomeClass B;
SomeDerivedClass C;
return 0;
}
在所有这三种情况下总计为3,或者对于2为SomeClass
1是SomeDerivedClass
?