OOPortal 





Operator Overloading  «Prev 
Unary and binary operator overloading

Nonstatic member functions

Data members can be declared with the storage class modifier static. A data member that is declared static is shared by all variables of that class and is stored uniquely in one place. Since a static member is independent of any particular instance, it can be accessed in the form

static Storage Class

The static storage class instructs the compiler to keep a local variable in existence during the life-time of the program instead of creating and destroying it each time it enters and leaves scope. Therefore, making local variables static allows them to maintain their values between function calls.
The static modifier may also be applied to global variables. When this is done, it causes that variable's scope to be restricted to the file in which it is declared.
In C++, when static is used on a class data member, it causes only one copy of that member to be shared by all objects of its class.

class name :: identifier 
Non-static members in C++
Nonstatic members are created for each instance of the class.
The
  1. assignment,
  2. function call,
  3. subscripting, and
  4. class pointer
operators can be overloaded only by nonstatic member functions.
Pointers to members (data and functions) work differently from other pointers. The syntax for declaring a pointer to a nonstatic data member or a nonstatic member function requires a class name and scope operator before the asterisk. Pointers to members can never be cast to ordinary pointers, and vice versa. You cannot declare a reference to a member.
A pointer to a static member is an ordinary pointer, not a member pointer. The following are some simple examples of member pointers:
struct simple {
 int data;
 int func(int);
};
int simple::* p = &simple::data;
int (simple::*fp)(int) = &simple::func;
simple s;
s.*p = (s.*fp)(42);