继承代码的C ++错误(没有匹配的构造函数)

时间:2015-03-25 19:28:26

标签: c++ inheritance constructor

我正在根据继承权为我的计算机科学课程完成一项任务,并且已经遇到了一个我似乎无法解决的错误。如果你们中的任何人能够引导我解决那些错误的错误!谢谢!

这是我的错误报告

  

main.cpp:199:21:错误:没有匹配的构造函数用于初始化' Faculty'     ......教师(" Nancy"," San Bernardino"," 555-555-5555"," nancy@coolpeople.com", " CSE"," 5000。"," 9月27日","教授","访问"));

     

main.cpp:169:10:注意:候选构造函数不可行:需要0个参数,         但提供了9个   学院师资::()            ^

     

main.cpp:175:10:注意:候选构造函数不可行:需要10个参数,         但提供了9个   Faculty :: Faculty(字符串n,字符串a,字符串t,字符串e,字符串o,strin ...            ^   
main.cpp:156:7:注意:候选构造函数(隐式复制构造函数)不是         可行:需要1个参数,但提供了9个参数   class Faculty:公共员工

这是我的代码:

#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","john@adams.com"));
  v.push_back(new Student("John Quincy Adams","Boston","617-555-0000","johnq@adams.com","senior"));
  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("Nancy","San Bernardino","555-555-5555","nancy@coolpeople.com","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;
}

我很感激能得到任何帮助!!

1 个答案:

答案 0 :(得分:3)

您的Faculty构造函数需要10个字符串;你只提供了9个(正如消息所说)。