please help

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include <iostream>
#include <string>
#include <vector>
using namespace std;

class Person{
public:
Person();
Person(string n, string a, string p, string e);
string getname(){return name;}
string getaddress(){return address;}
string getphone(){return phone;}
string getemail(){return email;}
virtual string whatami();
private:
string name;
string address;
string phone;
string email;
};

Person::Person(){
name = "name";
address = "address";
phone = "phone";
email = "email";
}

Person::Person(string n, string a, string p, string e){
name = n;
address = a;
phone = p;
email = e;
}
string Person::whatami()
{
return Person;
}

class Student : public Person{
public:
Student();
Student(string n, string a, string p, string e, string i, string y);
string getid(){return id;}
string getyear(){return year;}
virtual string whatami();
private:
string id;
string year;
};

Student::Student():Person(){
id = "id";
year = "year";
}

Student::Student(string n, string a, string p, string e, string i, string y):Person(n, a, p, e){
id = i;
year = y;
}
string Student::whatami()
{
return Student;
}


class Employee : public Person{
public:
Employee();
Employee(string n, string a, string p, string e, string o, string s, string h);
string getoffice(){return office;}
string getsalary() {return salary;}
string gethiredate() {return hiredate;}
virtual string whatami();
private:
string office;
string salary;
string hiredate;
};

Employee::Employee():Person(){
office = "office";
salary = "salary";
hiredate = "hiredate";
}

Employee::Employee(string n, string a, string p, string e, string o, string s, string h):Person(n, a, p, e){
office = o;
salary = s;
hiredate = h;
}
string Employee::whatami()
{
return Employee;
}


class Staff : public Employee{
public:
Staff();
Staff(string n, string a, string p, string e, string o, string s, string h, string pos);
string getposition(){return position;}
virtual string whatami();
private:
string position;
};

Staff::Staff(){
position = "position";
}

Staff::Staff(string n, string a, string p, string e, string o, string s, string h, string pos):Employee(n, a, p, e, o, s, h){
position = pos;
}
string Staff::whatami()
{
return Staff;
}

using namespace std;

class Faculty : public Employee{
public:
Faculty();
Faculty(string n, string a, string p, string e, string o, string s, string h, string r, string st);
string getrank(){return rank;}
string getstatus(){return status;}
virtual string whatami();
private:
string rank;
string status;
};

Faculty::Faculty():Employee(){
rank = "rank";
status = "status";
}

Faculty::Faculty(string n, string a, string p, string e, string o, string s, string h, string r, string st):Employee(n, a, p, e, o, s, h){
rank = r;
status = st;
}
string Faculty::whatami()
{
return Faculty;
}

class StaffST : public Student, public Staff{
public:
StaffST();
StaffST(string n, string a, string p, string e, string i, string y, string o, string s, string h, string pos, int ch);
int getcredithours(){return credithours;}
virtual string whatami();
private:
int credithours;
};

StaffST::StaffST(){
credithours = 0;
}

StaffST::StaffST(string n, string a, string p, string e, string i, string y, string o, string s, string h, string pos, int ch):Student(n, a, p, e, i, y),Staff(n, a, p, e, o, s, h, pos){
credithours = ch;
}
string StaffST::whatami()
{
return StaffST;
}

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","0098765","senior"));
v.push_back(new Employee("John Smith","Boston","617-555-0000","johns@adams.com","brewhouse 2","1000","9-15-1759"));
v.push_back(new Staff("Samuel Adams","Boston","617-555-BEER","sam@adams.com","brewhouse 1","1000","9-15-1764","Brewer"));
v.push_back(new Faculty("John Samuel Adams","Boston","617-555-BEER","johns@adams.com","brewhouse 3","1000","9-15-1769","Assistant","Brewer"));
v.push_back(new StaffST("John Adams Smith","Boston","617-555-BEER","johnsmith@adams.com","0012345","junior","brewhouse 5","100","9-15-1774","Taster",15));

StaffST ss("StaffST","2034 Work Way","961 229 1292","StaffST@gmail.com","008382976", "Junoir","129k","10,000","01/02/2011","Janitorial",37);
   cout << ss.whatami() << ": " << endl;

   cout << "Name: " << ss.Staff::getname() << endl;  //notice the Staff::
   cout << "Address: " << ss.Staff::getaddress() << endl;
   cout << "Phone: " << ss.Staff::getphone() << endl;
   cout << "Email: " << ss.Staff::getemail() << endl;

   cout << "Office: " << ss.getoffice() << endl;
   cout << "Salary: " << ss.getsalary() << endl;
   cout << "Hire Date: " << ss.gethiredate() << endl;
   cout << "Position: " << ss.getposition() << endl;
   cout << "ID: " << ss.getid() << endl;
   cout << "Year: " << ss.getyear() << endl;
   cout << "Credithours: " << ss.getcredithours()<< endl <<endl;
}


and when i run it this is what i get

1
2
3
4
5
6
7
8
9
10
11
12
13
14
whatami.cpp: In member function \u2018virtual string Person::whatami()\u2019:
whatami.cpp:37: error: expected primary-expression before \u2018;\u2019 token
whatami.cpp: In member function \u2018virtual string Student::whatami()\u2019:
whatami.cpp:63: error: expected primary-expression before \u2018;\u2019 token
whatami.cpp: In member function \u2018virtual string Employee::whatami()\u2019:
whatami.cpp:94: error: expected primary-expression before \u2018;\u2019 token
whatami.cpp: In member function \u2018virtual string Staff::whatami()\u2019:
whatami.cpp:117: error: expected primary-expression before \u2018;\u2019 token
whatami.cpp: In member function \u2018virtual string Faculty::whatami()\u2019:
whatami.cpp:145: error: expected primary-expression before \u2018;\u2019 token
whatami.cpp: In member function \u2018virtual string StaffST::whatami()\u2019:
whatami.cpp:167: error: expected primary-expression before \u2018;\u2019 token
whatami.cpp: In function \u2018int main()\u2019:
whatami.cpp:178: error: \u2018Person\u2019 is an ambiguous base of \u2018StaffST\u2019
This:
1
2
3
4
string Person::whatami()
{
return Person;
}

should be:
1
2
3
4
string Person::whatami()
{
    return "Person";
}
@kbw

thanks it fixed the errors but i still get one error

whatami.cpp:178: error: \u2018Person\u2019 is an ambiguous base of \u2018StaffST\u2019
It has to do with multiple inheritance, where it is ambiguous if StaffST is more a Student - Person or Staff - Person.
Quoting someone from another forum:
This:
http://yosefk.com/c++fqa/inheritance-mu ... l#fqa-25.8
is your problem, and this:
http://yosefk.com/c++fqa/inheritance-mu ... l#fqa-25.9
is your solution.
Topic archived. No new replies allowed.