Access Control Example
private: // For our eyes only!
employee(); // Constructors MUST be public!
~employee(); // (and destructors too)
void set_name(char *name);
char *name() { return name_p; }
employee::employee() { // Constructor!
// New set_name() does proper memory mgmt!
employee::set_name(char *name) {
employee::~employee() { // Destructor!
employee e, e2; // Constructors called
e.set_name(“Jim Smith”); // free() done!
printf(“Name is %s!\n”, e.name());
// This FAILS at compile-time!
} // Destructors called here!
(Note, I’m glossing over the fact that the caller can still change the contents of the string to which name_p points, if not the pointer itself)