Are static members inherited? (C++)

Posted by Keand64 on Stack Overflow See other posts from Stack Overflow or by Keand64
Published on 2009-06-15T20:38:31Z Indexed on 2011/01/12 6:53 UTC
Read the original article Hit count: 160

Filed under:
|
|

When static members are inherited, are they static for the entire heirarchy, or just that class, ie:

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;
}

would total be 3 in all three instances, or would it be 2 for SomeClass and 1 for SomeDerivedClass?

© Stack Overflow or respective owner

Related posts about c++

Related posts about inheritance