Derived Classes (Segmentation Fault)

I have this assignment that uses classes that derive from other classes, but for some reason I can't get pass a segmentation fault. Here is the code:

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
#include <vector>
#include <iostream>

using namespace std;

//Person Class
class Person
{
  private:
    string name;
    string address;
    string telephone;
    string email;
  
  public:
    Person(string n, string a, string t, string e);
    string getName();
    string getAddress();
    string getTelephone();
    string getEmail();
};

Person::Person(string n, string a, string t, string e)
{
  name = n;
  address = a;
  telephone = t;
  email = e;
}

string Person::getName()
{
  return name;
}

string Person::getAddress()
{
  return address;
}

string Person::getTelephone()
{
  return telephone;
}

string Person::getEmail()
{
  return email;
}

//-----------------------------------------------------

//Student Class
class Student : public Person
{
  private:
    string education;
  
  public:
    Student(string n, string a, string t, string e, string edu);
    string getEducation();
};

Student::Student(string n, string a, string t, string e, string edu) : Person (n, a, t, e)
{
  Student(n, a, t, e, edu);
  string education = edu;
}

string Student::getEducation()
{
  return education;
}


//--------------------------------------------------------

//Employee Class
class Employee : public Person
{
  private:
    string office;
    double salary;
    string hdate;
  
  public:
    Employee(string n, string a, string t, string e, string office, double salary, string hdate);
    string getOffice();
    double getSalary();
    string getHdate();
};

Employee::Employee(string n, string a, string t, string e, string office, double salary, string hdate) : Person(n, a, t, e)
{
  Employee(n, a, t, e, office, salary, hdate);
  this -> office = office;
  this -> salary = salary;
  this -> hdate = hdate;
}

string Employee::getOffice()
{
  return office;
}

double Employee::getSalary()
{
  return salary;
}

string Employee::getHdate()
{
  return hdate;
}


//------------------------------------------------------------
//Faculty Class
class Faculty : public Employee
{
  private:
    string status;
    string rank;
  
  public:
    Faculty(string n, string a, string t, string e, string office, double salary, string hdate, string rank, string status);
    string getRank();
    string getStatus();
};

Faculty::Faculty(string n, string a, string t, string e, string office, double salary, string hdate, string rank, string status) : Employee(n, a, t, e, office, salary, hdate)
{
  Faculty(n, a, t, e, office, salary, hdate, rank, status);
  this -> rank = rank;
  this -> status = status;
}

string Faculty::getRank()
{
  return this -> rank;
}

string Faculty::getStatus()
{
  return this -> status;
}

//--------------------------------------------------------------
//Staff Class
class Staff : public Employee
{
  private:
    string job;
    
  public:
    Staff(string n, string a, string t, string e, string office, double salary, string hdate, string job);
    string getJob();
};

Staff::Staff(string n, string a, string t, string e, string office, double salary, string hdate, string job) : Employee(n, a, t, e, office, salary, hdate)
{
  Staff(n, a, t, e, office, salary, hdate, job);
  this -> job = job;
}

string Staff::getJob()
{
  return job;
}

//--------------------------------------------------------------

int main()
{
  Person john("John","15695 Blocke St.","951-1513","Carmelosf@met.com");
  cout << john.getName() << endl;
  
  Student mark("Mark","15695 Blocki St.","951-2513","Carmelosf@mey.com", "Sophmore");
  cout << mark.getEducation() << endl;
  
  Employee david("David","15695 Blockaq St.","951-3513","Carmelosf@meu.com", "Room9", 25, "Jan 29 2009");
  cout << david.getHdate() << endl;
  
  Faculty mike("Mike","15695 Blocku St.","951-4513","Carmelosf@mei.com", "His Office", 21, "Jan 29 2009", "Professor", "Tenured");
  cout << mike.getStatus() << endl;
  
  Staff mei("Mei","15695 Blocky St.","951-5513","Carmelosf@mel.com", "My Office", 21, "Manager of McDonalds", "Jan 29 2009");
  cout << mei.getJob() << endl;
}


It outputs:

John
Segmentation fault (core dumped)


I'm not sure what I'm doing wrong when setting it up. Sorry for the long line of code.
Last edited on
If you bother yourself to run through a debugger, you'll notice that you have an stack overflow, produced by
1
2
3
4
5
Student::Student(string n, string a, string t, string e, string edu) : Person (n, a, t, e)
{
  Student(n, a, t, e, edu); //¿what do you think you are doing here?
  string education = edu;
}
The way the assignment was set up was to inherit the public portion of the classes and display how to output them even if the function was not in the inherited class.
Let me rephrase that. The Student class inherits from the Person class, so "name = n", "address = a", ect. Then in the main function, I just fill in the positions to be outputted. Then for the second assignment, we implement virtual classes.
What do you think line 66 is doing?
Whoa... Okay, I see what happened. I have to rewrite my notes, I confused myself into thinking I needed to add Student(blah blah blah), Employee(blah)... Thanks you guys!
Topic archived. No new replies allowed.