inheritance

Hey hoping you guys can give me a push in the right direction. I can enter information up til position, after that the s system stops working cause of error. Have not been able to figure it out. Any advise would be appreciated.

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
 #include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>

using namespace std;

class name 
{
 
protected:  

   char *first, *last;  

public:  

        name() {}; 

        name(char *f, char *l): first (f), last (l){}
                  
        virtual void info()
		{
               
             info();
          
        } 
        void Print (void)   
        {                                       
            cout <<  "The first name is" << setw(22) << first << endl;
            cout << "The last name is" << setw(22) << last << endl;
		}
 };  

class person : public name 
{

	char gender;  

	int  ssn;

public:

	person() {};  

	person(char *f, char *l, char g, int s): gender(g), ssn(s), name::name(f, l) {}

	virtual void info() 
	{ 

        name::info();
    }
	void Print (void) 
	{
         cout << "The gender is" << setw(22) << gender << endl;
         cout << "The social security number is" << setw(22) << ssn<< endl;
	}
};  

class employee : public person 
{  

protected:  

	int payroll;

	char *position;

public:

   employee() {};     

   employee(char *f, char *l, char g, int s, int p, char *pos): payroll(p), position (pos), person::person(f,l,g,s) {}

	void info() 
	{ 
		employee::info();
		
	}
 
	void Print (void) 
	{
    
    	cout << "The payroll is" << setw(22) << payroll << endl;
    	cout << "The position is" << setw(22) << position << endl;     
    }
};  
int main()  

{

char fn[20], ln[20], pos[20];

char gen;

int s, pay;

name *worker;

for (int i=0; i<3; i++) 
	{

    	cout << "Input the first name: " << endl;

    	cin >> fn;

    	cout << "Input the last name: " << endl;

    	cin >> ln;    

    	cout << "Input the gender: " << endl;

    	cin >> gen;

    	cout << "Input the social security number: " << endl;

    	cin >> s;   

    	cout << "Input the payroll: " << endl;

    	cin >> pay;

    	cout << "Input the position: " << endl;

    	cin >> pos;   

    	worker = new employee(fn, ln, gen, s, pay, pos);

    	worker->info();

    }

    system("pause");

    return 0;

}
1
2
3
4
5
//class employee
void info()
{
	employee::info();
}
Guess which function it is going to call? So you got classic infinite recursion and subsequent stack overflow.
thanks i updated to

person::info();

but i'm still getting the same error.
Check other functions, say, in name class
Topic archived. No new replies allowed.