question

i have this two class as inhertance. i want to know please how can i send all the staff in print in class 1 to class 2 and inaddion to the staff in class 2?

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
class works{
string first_name;
string last_name;
string work_name;
public:
works(string f,string l,string w){
first_name=f;
last_name=l;
work_name=w;
}
void print(){
cout<<"the first name is :"<<f;
cout<<"the last name is :"<<l;
cout<<"the work name is :"<<w;
}
};
 class employee:public works{
int hour;
public:
employee(string f,string l,string w,int h):works(f,l,w),employee(h){}
double cal(){
double salary;
return salary=hour*12;
void print(){
cout<<"the hour work is :<<cal();  


how can i send the first print fun in first class with all the staff inside to print fun in employee class with salary inaddtion.
the out put should be after main be like :

the first name is : ricardo
the last name is : ageil
the work name is : call center
the hour work is :37

thank you
1) You do not have employee constructor taking one parameter.
Line 20 should be: employee(string f,string l,string w,int h):works(f,l,w), hour(h){}

2) You can call base class methods by explicitely qualifying them:
1
2
3
4
5
void print()
{
    works::print();
    cout<<"the hour work is :<<cal();  
) 


3) If you want to use polymorphism, make print() virtual.
Topic archived. No new replies allowed.