The programmer must note the following while using static member functions:
A static member function can only access static member data, static member functions and data and functions outside the class. The programmer must take note not to use static member function in the same manner as non-static member function, as non-static member function can access all of the above including the static data member.
.
A non-static member function can be declared as virtual but care must be taken not to declare a static member function as virtual.
.
The programmer must first understand the concept of static data while learning the context of static functions. It is possible to declare a data member of a class as static irrespective of it being a public or a private type in class definition. If a data is declared as static, then the static data is created and initialized only once. Non-static data members are created again and again. For each separate object of the class, the static data is created and initialized only once. As in the concept of static data, all objects of the class in static functions share the variables. This applies to all objects of the class.
.
A non-static member function can be called only after instantiating the class as an object. This is not the case with static member functions. A static member function can be called, even when a class is not instantiated.
.
A static member function cannot have access to the 'this' pointer of the class.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment