Hello Every one.
Here I can do conversion from emp
class object to emp
class object. But I can't do conversion from employee
class object to emp
class object - I have added comment where I am getting error - 'setEmpID' is not a member of 'employee'
. what should I do to resolve this error ? ( I am just preparing for C++ exam & this is the only one that I couldn't solve )
Edit - see this is the definition of program - There are two classes Emp and Employee.Emp is defined in the payroll department containing details about employee id and details about his/her payment. Employee isHuman resource department class containing only basic salary details and full personal details like name of spouse, number of children, previous experience of an employee etc. Add code in the Emp class such that, conversion from one type of employee object into another is possible. While converting, items which are not here in the source class (like No. of children when source class is Employee) should take a default value.
#include<iostream.h>
#include<conio.h>
#include<string.h>
class employee;
class emp
{
private:
unsigned int empID;
public:
emp(){
empID=0;
}
emp(unsigned int x){
empID=x;
}
emp(employee tmp) {
// i am getting error here.
tmp.setEmpID(10);
}
void setEmpID(unsigned int x){
empID=x;
}
int getEmpID(){
return empID;
}
};
class employee : public emp {
private:
char name[30];
public:
employee();
employee(unsigned int x);
employee(unsigned int x,char y[]);
employee(emp tmp);
void display();
};
employee :: employee()
{
emp();
name[0]='\0';
}
employee :: employee(unsigned int x)
{
emp(x);
name[0]='\0';
}
employee :: employee(unsigned int x,char y[]) : emp(x)
{
strcpy(name,y);
}
employee :: employee(emp tmp) : emp( tmp.getEmpID() )
{
name[0]='\0';
}
void employee :: display(){
cout<<"No is -> "<<getEmpID()<<endl<<"Name -> "<<name;
}
void main() {
clrscr();
emp e1(10);
employee e2(10u,"nimita");
cout<<e1.getEmpID()<<endl;
e2.display();
getch();
}
Thanks in advance for sharing your great knowledge
.
Sugar