Summary

In this hour, you learned how to create static member variables in your class. Each class, rather than each object, has one instance of the static member variable. It is possible to access this member variable without an object of the class type by fully qualifying the name, assuming you've declared the static member to have public access.

Static member variables can be used as counters across instances of the class. Because they are not part of the object, the declaration of static member variables does not allocate memory, and static member variables must be defined and initialized outside the declaration of the class.

Static member functions are part of the class in the same way that static member variables are. They can be accessed without a particular object of the class and can be used to access static member data. Static member functions cannot be used to access non-static member data because they do not have a this pointer.

Because static member functions do not have a this pointer, they also cannot be made const. const in a member function indicates that the this pointer is const.

In this hour, you also saw how to delegate functionality to a contained object. Containment is restricted in that the new class does not have access to the protected members of the contained class, and it cannot override the member functions of the contained object.

You saw how to declare both friend functions and friend classes. Friend classes should be used with caution, but they can help you find a middle ground between providing access only to the member methods of a class and making methods and data public.

Finally, you saw how to create pointers to functions and pointers to member functions, and how to use those pointers to invoke methods dynamically.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.129.59