cppannotations/annotations/yo/pointermembers/intro.yo
Frank B. Brokken 777b182edd Moved all files but 'excluded', 'sf', and 'sourcetar' to ./annotations
This allowed me to standardize the sourcetar and sf/* scripts: the base
    directory (containing ./git) is now empty, except for maintenance scripts,
    while the source files and build scripts of the annotations are stored in
    a subdirectory of their own.
2013-05-29 20:44:08 +02:00

26 lines
1.6 KiB
Text

Classes having tt(pointer data members) have been discussed in detail in
chapter ref(MEMORY). Classes defining pointer data-members deserve some
special attention, as they usually require the definitions of copy
constructors, overloaded assignment operators and destructors
Situations exist where we do not need a pointer to an object but rather a
i(pointer to members) of a class. Pointers to members can profitably be used
to configure the behavior of objects of classes. Depending on which member a
pointer to a member points to objects will show certain behavior.
Although pointers to members have their use, polymorphism can frequently be
used to realize comparable behavior. Consider a class having a member
tt(process) performing one of a series of alternate behaviors. Instead of
selecting the behavior of choice at object construction time the class could
use the interface of some (abstract) base class, passing an object of some
derived class to its constructor and could thus configure its behavior. This
allows for easy, extensible and flexible configuration, but access to the
class's data members would be less flexible and would possibly require the use
of `friend' declarations. In such cases pointers to members may actually be
preferred as this allows for (somewhat less flexible) configuration as well as
direct access to a class's data members.
So the choice apparently is between on the one hand ease of configuration and
on the other hand ease of access to a class's data members. In this chapter
we'll concentrate on pointers to members, investigating what these pointers
have to offer.