Control class access

Assign private and protected to special member functions to control access and use of your class.

Type of control Controlled by making...
Only derived classes can call them Some constructors protected
The object cannot be copied Assignment and copy constructor private
Only derived classes can copy the object Assignment and copy constructor protected
Clients cannot delete the object directly or allocate it on the stack Destructors private or protected
Client cannot allocate object on the heap Operator new private or protected

Remember, C++ has access control, not visibility control, so making something private means it's still defined, but some clients can't use it.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker