Syntax error on inheritance (derived classes)

So, I'm basically trying to define a base class person that will contain universal
information, including name, address, birth date, gender and identification
(student, worker etc). Derive from this class the following classes:

Student

Worker

Student_worker (derived from student and worker)


I need to add variable school to student and company to worker class.

In the main function I have to create a structure that will be able to hold all types of objects. Letting user enter several objects of different type (create those objects dynamically) and sort the structure by gender and by type.
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
  #include <iostream>
#include <string>

using namespace std;

class Person
{
public: 
	Person ();
private: 
	string Name;
	string Address;
	string Birth_Date;
	string Gender;
	string ID;
};
Person::Person () 
{
	Name = " ";
	Address = " "; 
	Birth_Date = " ";
	Gender = " ";
	ID = " ";
}

class Student: public Person
{
public:
	string school;
};

class Worker: public Person
{
public:
	string company;
};

class Student_Worker: public Student, public Worker
{
public:
	//Student_Worker () {;} // Constructor overide?
};

int main ()
{
	//system("color 0A");
	int x = 0;
	string continue;
	
	while (continue != "N")
	{
	Person [x];
	
	cout<< "Enter your First Name, Address, Birth Date (mm/dd/yy)
, Gender, and ID (student 'S', worker 'W', or both 'B')." << endl;
	cin>> [x].Name >> [x].Address >> [x].Birth_Date >> [x].Gender >> [x].ID;
	cout<< "Enter another person? (Y/N) : ";
	cin>> continue;
	x++;
	}
	
	cout<< "Veiw list by Gender or Identification? (G/I) : ";
	cin>> continue;
	if (continue == "G")
	{
		for (i=0; i<10; i++)
		{
			cout<< [i].Name << " : " << [i].Gender << endl;
		}
	}
	else
	{
		for (i=0; i<10; i++)
		{
			cout<< [i].Name << " : " << [i].ID << endl;
		}
	}
	
	cout<< endl;
	//system("pause");
	return 0;
}
Last edited on
continue is a reserved keyword in C/C++ and can't be used as a variable name
Topic archived. No new replies allowed.