Reputation: 1
I'm working on an assignment for my Computer Science class based on inheritence and have been getting this one error that I can't seem to fix. If any of you could walk me through what's wrong that would be great! Thank you!
This is my Error Report
main.cpp:199:21: error: no matching constructor for initialization of 'Faculty' ...Faculty("Nancy","San Bernardino","555-555-5555","[email protected]","CSE", "5000.","September 27th","Professor","visiting"));
main.cpp:169:10: note: candidate constructor not viable: requires 0 arguments, but 9 were provided Faculty::Faculty() ^
main.cpp:175:10: note: candidate constructor not viable: requires 10 arguments, but 9 were provided Faculty::Faculty(string n, string a, string t, string e, string o, strin... ^
main.cpp:156:7: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 9 were provided class Faculty : public Employee
And this is my code:
#include <string>
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
class Person
{
public:
Person();
Person(string n, string a, string t, string e);
string getName();
string getAddress();
string getTelephone();
string getEmail();
virtual string whatami();
private:
string n;
string a;
string t;
string e;
};
Person::Person(){}
Person::Person(string n, string a, string t, string e)
{
this->n=n;
this->a=a;
this->t=t;
this->e=e;
}
string Person::getName()
{
return n;
}
string Person::getAddress()
{
return a;
}
string Person::getTelephone()
{
return t;
}
string Person::getEmail()
{
return e;
}
string Person::whatami()
{
return "Person";
}
class Student : virtual public Person
{
public:
Student();
Student(string n, string a, string t, string e, string s);
string getStatus();
virtual string whatami(){return "Student";};
private:
string status;
};
Student::Student()
{
string status = "";
}
Student::Student(string n, string a, string t, string e, string s) : Person(n,a,t,e)
{
status = s;
}
string Student::getStatus()
{
return status;
}
class Employee : virtual public Person
{
public:
Employee();
Employee(string n, string a, string t, string e, string o, string p, string d);
string getOffice();
string getPayment();
string getDatehired();
virtual string whatami(){return "Employee";};
private:
string office;
string payment;
string datehired;
};
Employee::Employee()
{
string office = " ";
string payment = " ";
string datehired = " ";
}
Employee::Employee(string n, string a, string t, string e, string o, string p, string d) : Person(n,a,t,e)
{
office = o;
payment = p;
datehired = d;
}
string Employee::getOffice()
{
return office;
}
string Employee::getPayment()
{
return payment;
}
string Employee::getDatehired()
{
return datehired;
}
class Staff : virtual public Employee
{
public:
Staff();
Staff(string n,string a, string t, string e, string o, string s, string d, string j);
string getJobtitle();
virtual string whatami(){return "Staff";};
private:
string jobtitle;
};
Staff::Staff()
{
jobtitle = "";
}
Staff::Staff(string n, string a, string t, string e, string o, string p, string d, string j) : Person(n,a,t,e),Employee(n,a,t,e,o,p,d)
{
jobtitle = j;
}
string Staff::getJobtitle()
{
return jobtitle;
}
class Faculty : public Employee
{
public:
Faculty();
Faculty(string n, string a, string t, string e, string o, string p, string d, string j, string r, string f);
string getRank();
string getStatus();
virtual string whatami(){return "Faculty";};
private:
string rank;
string fstatus;
};
Faculty::Faculty()
{
rank = "";
fstatus = "";
}
Faculty::Faculty(string n, string a, string t, string e, string o, string p, string d, string j, string r, string f) : Person(n,a,t,e),Employee(n,a,t,e,o,p,d)
{
rank = r;
fstatus = f;
}
string Faculty::getRank()
{
return rank;
}
string Faculty::getStatus()
{
return fstatus;
}
int main()
{
vector<Person*> v;
v.push_back(new Person("John Adams","Boston","617-555-0000","[email protected]"));
v.push_back(new Student("John Quincy Adams","Boston","617-555-0000","[email protected]","senior"));
v.push_back(new Staff("Samuel Adams","Boston","617-555-BEER","[email protected]","brewhouse 1","1000","9-15-1764","Brewer"));
v.push_back(new Faculty("Nancy","San Bernardino","555-555-5555","[email protected]","CSE", "5000.","September 27th","Professor","visiting"));
for (int i=0; i<v.size(); i++)
{
cout << v[i]->getName() << " " <<v[i]->getAddress() << " " << v[i]->getTelephone() << " " << v[i]->getEmail() << " " << classify(v[i]) <` endl;
}
return 0;
}
I would be grateful to get any help that I can!!
Upvotes: 0
Views: 186
Reputation: 49803
Your Faculty
constructor expects 10 strings; you provided only 9 (just as the message says).
Upvotes: 3