What is the issue in this inheritence cpp problem

Viewed 47
class Temporary_Employee: public Employee{
    //consolidated monthly pay
    public:
        
    int con_pay;
    int sal;
    Temporary_Employee(string name,int num,string des,int cp) :Employee(name,num,des){
        con_pay=cp;
    }
        void salary(){
            sal=con_pay;
        }
        
        void display_t(){
            cout<<"Name: "<<employee_name<<endl;
            cout<<"Number: "<<employee_no<<endl;
            cout<<"Designation: "<<desig<<endl;
            cout<<"Monthly Salary: "<<sal<<endl;
        }
};

I'm getting error:'Employee::Employee(std::string, int, std::string)' is private within this context

2 Answers

The data members (name,num,des) in your 'Employee' class should be specified as public.

It seems like you need make the data members in you "Employee" class as public. like this

Employee(...){
 public:
     {data members}
}
Related