Академический Документы
Профессиональный Документы
Культура Документы
4.1 friend
Allows global functions and any or all member functions of other classes access to the
private parts of a class. Only use this to achieve a significant optimization or as
alternative method (to subclassing) for implementing systems of objects. It breaks down
the encapsulation feature of C++ classes, so it should be used with care. Subclassing and
member functions are preferred. Here's where making a constructor private could make
sense.
mult
examples
Alternatives using member functions and inline functions. friend mechanism provides
significant optimization since public interface functions do array bounds checking on
accesses. Otherwise, inline functions do the job fine, and no special friend access needed
for efficiency.
4.2 Arrays of class objects
Special notations. Special deletion syntax we've seen.
4.3 Pointers to members
X::* syntax. Apply address operator to member accessed through type rather than object
- & X::memb. Access using .* or ->*. In many cases, virtual functions obviate the