// This code illustrates “diamond” inheritance. // Jack has two jobs, The Fort Collins Club (FCC) and CSU. // Both of the derived classes inherit virtually from worker. // Therefore, Jack has only one social security number (ss_num), // which is good. Note that Worker::Worker() only gets called once. #include using namespace std; class Worker { public: Worker() { clog << __PRETTY_FUNCTION__ << '\n'; } int ss_num; }; class CSU_Employee : virtual public Worker { public: int employee_id; }; class FCC_Employee : virtual public Worker { public: int employee_id; }; class Jack : public CSU_Employee, public FCC_Employee { public: int number_of_comics; }; int main() { Jack j; j.ss_num = 323456789; // OK // Worker *w = &j; // CSU_Employee *c = &j; // FCC_Employee *f = &j; }