Home > other >  What is the issue in this inheritence cpp problem
What is the issue in this inheritence cpp problem

Time:09-18

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

CodePudding user response:

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

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

CodePudding user response:

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

  • Related