#include <string>
#include <iostream>
#include <vector>
using namespace std;

class Person {
public:
    Person();
    Person(string n, string a, string tel, string em);
    string getName();
    string getAddress();
    string getTel();
    string getEmail();
    virtual string whatAmI();
private:
    string name, address, telephone, email;
};
Person::Person() {

}
Person::Person(string n, string a, string tel, string em) {
    name = n;
    address = a;
    telephone = tel;
    email = em;
}
string Person::getName() {
    return name;
}
string Person::getAddress() {
    return address;
}
string Person::getTel() {
    return telephone;
}
string Person::getEmail() {
    return email;
}
string Person::whatAmI() {
    return "Person";
}
//Class Student derived from Person
class Student: virtual public Person {
public:
    Student(string n, string a, string tel, string em, string cstat);
    virtual string whatAmI();
private:
    string classStatus;
};
Student::Student(string n, string a, string tel, string em, string cstat): 
Person(n, a, tel, em), classStatus(cstat) {

}
string Student::whatAmI() {
    return "Student";
}
//Class Employee derived from Person
class Employee: public Person {
public:
    Employee(string n, string a, string tel, string em, string of, double sal, string date);
    virtual string whatAmI();
private:
    string office, dateHired;
    double salary;
};
Employee::Employee(string n, string a, string tel, string em, string of, double sal, string date):
Person(n, a, tel, em), office(of), salary(sal), dateHired(date) {

}
string Employee::whatAmI() {
    return "Employee";
}
//Class Faculty derived from Employee
class Faculty: public Employee {
public:
    Faculty(string n, string a, string tel, string em, string of, double sal, string date, string fr, string fstat);
    virtual string whatAmI();
private:
    string frank, fstatus;
};
Faculty::Faculty(string n, string a, string tel, string em, string of, double sal, string date, string fr, string fstat):
Employee(n, a, tel, em, of, sal, date), frank(fr), fstatus(fstat) {

}
string Faculty::whatAmI() {
    return "Faculty";
}
//Class Staff derived from Employee
class Staff: public Employee {
public:
    Staff(string n, string a, string tel, string em, string of, double sal, string date, string title);
    virtual string whatAmI();
private:
    string jobtitle;
};
Staff::Staff(string n, string a, string tel, string em, string of, double sal, string date, string title): 
Employee(n, a, tel, em, of, sal, date), jobtitle(title) {

}
string Staff::whatAmI() {
    return "Staff";
}
class StaffST: public Staff, public Student {
public:
    StaffST(string n, string a, string tel, string em, string of, double sal , string date, string title, string cstat, int chours);
    virtual string whatAmI();
private:
    int credithrs;
};
StaffST::StaffST(string n, string a, string tel, string em, string of, double sal , string date, string title, string cstat, int chours):
Staff(n, a, tel, em, of, sal, date, title), Student(n, a, tel, em, cstat), credithrs(chours) {

}
string StaffST::whatAmI() {
    return "StaffST";
}
string classify(Person* p) {
    return p->whatAmI();
}
int main () {
    vector<Person*> v;
    v.push_back(new Person("John Adams","Boston","617-555-0000","john@adams.com"));
    v.push_back(new Student("John Quincy Adams","Boston","617-555-0000","johnq@adams.com","senior"));
    v.push_back(new Faculty("John Doe", "123 Citrus Dr.", " 909-255-0002","Jdoe@email.com", " Room 354", 46000, "January 24,2011", "Professor", "Tenured"));
    v.push_back(new Employee("John Smith", "123 coyote Dr.", " 909-255-0001", "john@yahoo.com", "Jack Brown 385", 50000, "June 13, 2005"));
    v.push_back(new Staff("Samuel Adams","Boston","617-555-BEER","sam@adams.com","brewhouse 1",25000," 5-3-08","Brewer"));
    v.push_back(new StaffST("Samuel Smith","Boston","617-555-BEER","samsmith@adams.com","brewhouse 5",100,"9-15-1774","Taster","junior", 12));

// Hey - no Faculty object ---> add one yourself!

   for (int i = 0; i < v.size(); i++)
     {
       cout << v[i]->getName() << "  " << classify(v[i]) << endl;
     }
    return 0;
}

I get an error that says "Person" is an ambiguous base of "StaffST"

Edited 3 Years Ago by kruschev: Omitted info.

I fixed the problem by ammending line 58 to this:

class Employee: virtual public Person {};

but now my output does this:

John Quincy Adams Student
Faculty
John Smith Employee
Staff
StaffST

Faculty, Staff, and StaffST don't display their names. Don't they inherit from Person?
Thank you for any help.

Is there a reason why you are using virtual inheritance for Student and Employee? That should only be necessary if you are inheriting from more than one class that has a common root class. This does not appear to be the case; however, that is not likely the cause of your problem.

That said, StaffST is derived from two classes that have a common root, so it should use virtual inheritance so it only has one instance of the root (Person) class. From my cursory view of your other class definitions, none of the others should be so encumbered, although you might want to define Student and Staff to have virtual inheritence of Person just to be clear. Compilers are picky things. BTW, what system/compiler are you using? Not all are standards-compliant... :-)

This article has been dead for over six months. Start a new discussion instead.