c++ - Are static members inherited? -


i have static member variable in class , class b derives class a.

class {   public:     a()     {       = 3;     }     static int a; };  int a::a = 0;  class b : public {   public:     b()     {       = 4;             } };  void main() {   obja;   cout << "before:" << a::a;   b obj;   cout << endl << "after:" << a::a; } 

as per are static fields inherited? when derived type object made creates base type. have following questions:

  1. how instead of a::a can access obja.a? static variables shouldn't accessible through objects of class.

  2. if derived class new static variable made (specific class b) why not necessary initialize static variable class b?

  3. why output of following shown as:

before:3

after:4

when expected show 3 before , after?

the access static variable inherited. note static members private access not accessible, protected keyword for.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -