Structs vs. Classes
// A plain vanilla C class (valid C++)
// Declare an instance of an employee
// Note the structure is a totally
// passive container for data
e.name = strdup(“John Doe”);
printf(“Name is: %s\n”, e.name);
printf(“Base pay is: %d\n”, e.base_pay);
printf(“%d days of leave since %d\n”,
e.leave_time, e.year_started);
public: // ignore this for now
// First declare the actual storage
// Now declare functions to access that storage;
// these are sometimes called “accessor functions”.
// Also: strdup is just a malloc/strcpy shortcut
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 e; // Instance of the employee class
printf(“Name is %s; base pay is %d\n”, e.name(),