Are static fields inherited?

前端 未结 7 1202
孤街浪徒
孤街浪徒 2020-11-28 02:44

When static members are inherited, are they static for the entire hierarchy, or just that class, i.e.:

class SomeClass
{
public:
    SomeClass(){total++;}
           


        
7条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 03:18

    Yes, the derived class would contain the same static variable, i.e. - they would all contain 3 for total (assuming that total was initialized to 0 somewhere).

提交回复
热议问题