Constructors and Destructors
public: // ignore this for now
void set_name(char *name) {name_p = strdup(name);}
char *name() { return name_p; }
void set_base_pay(int pay) { base_pay_p = pay; }
int base_pay() { return base_pay_p; }
employee::employee() { // Constructor!
base_pay_p = year_started_p = leave_time_p = 0;
employee::~employee() { // Destructor!
employee e; // Constructor is called!
employee e2; // Constructor again!
printf(“Name is %s; base pay is %d\n”, e.name(),
} // Destructors are called for e and e2!
Uh oh! This program will crash when e2’s destructor tries to call free(0xdeadbeef)! Wouldn’t it be nice if we could somehow protect our internal variables from outside access? I’m so glad you asked!!