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:
how instead of
a::acan accessobja.a? static variables shouldn't accessible through objects of class.if derived class new static variable made (specific
class b) why not necessary initialize static variableclass b?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
Post a Comment