Inheritance

I have a base class, and two derivaded class from that one...what I want to do is to have a class which inheritance everything togheter....the base class and the two derivaded class...here is my code...I though at the beggining that the problem came from default constructor, but I think It's not...
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
 
#include <stdio.h>
#include <iostream>

using namespace std;

class person{
	protected:
		string name;
		int age;
		string sex;
};

class student:public person{
	protected:
		string degree;
	public: 
		void set_values(const string& a,const int& b,const string& c,const string& d){
			name = a;
			age = b;
			sex = c;
			degree = d;
		}
};

class worker:public person{
	protected:
		string job;
	public:
		void set_values(const string& a,const int& b,const string& c,const string& d){
			name = a;
			age = b;
			sex = c;
			job = d;
			
		}
};


class graduate:public person,public worker,public student{
public:
		graduate():person(){};
		void set_values(const string& a,const int& b,const string& c,const string& d,const string& e){
			name = a;
			age = b;
			sex = c;
			degree = d;
			job = e;
			
		}

};

int main(int argc, char **argv)
{
	
}
graduate inherits from person AND worker AND student, but worker also inherits from person as well. and student inherits from person too!?
This is a messed up design.
Try drawing the classes you want and how you think the inheritance relationships should be on some paper first. This might help clarify things a little.
there is no need for graduate to directly inherit from all three above classes. If it inherits from worker and student, then it automatically inherits from person indirectly. The reason you can't compile your code that you gave us , is because the compiler has no clue what name , age and sex you are talking about when you try to assign them in the graduate class. You need to specify where they come from such as worker::name, or student::age. This is called ambiguous class members. Hope this helps
yes, It's just to learn....It doesnt have any specific goal, just I want to know If what I'm doing is possible...I guesss It shoudl be..
With those classes, explain in words the relationship. For example, once a person graduates they (hopefully) become a worker. in other words they are NOT a kind of student.


if it's just to learn i would stay away from multiple inheritance to begin with.
my idea is that GRADUATE person is somebody who is student while he is woking in a internship period, so That class should have all member declared at any class..

Erbisme4 I did that at the begining and it was what the compiler launched, but I dont know how to fix it...can It be because when I declare an object of Graduate It call constructor student and constructor worker, and they call to constructor person, so constructor person is called twice...
Topic archived. No new replies allowed.