I am a beginner in C++. I am working on inheritance. In my code, when I try to call the member function of the base class from the derived class, i get the error statement cannot resolve address of overloaded function. I have applied the scope operator and the member function of the base class is protected, so that the derived do not have problem to access the functions. What am I doing wrong here? Here is my code:
#include <iostream>
#include <string.h>
using namespace std;
class Employee
{
private:
char *emp_name;
int emp_code;
char *designation;
protected:
Employee(char *name ="",int code = 0,char *des = "", int nlength=1, int dlength=1): emp_code(code)
{
emp_name = new char[nlength+1];
strncpy(emp_name,name,nlength);
designation = new char[dlength+1];
strncpy(designation,des,nlength);
}
~Employee()
{
delete[] emp_name;
delete[] designation;
}
char* GetName()
{
return emp_name;
}
int GetCode()
{
return emp_code;
}
char* GetDes()
{
return designation;
}
};
class Work: public Employee
{
private:
int age;
int year_exp;
public:
Work(char *name ="", int code = 0, char *des = "", int nlength=1, int dlength=1, int w_age=0, int w_exp=0):Employee(name,code,des,nlength,dlength),age(w_age),year_exp(w_exp)
{
}
void GetName()
{
Employee::GetName;
}
void GetCode()
{
Employee::GetCode;
}
void GetDes()
{
Employee::GetDes;
}
int GetAge()
{
return age;
}
int GetExp()
{
return year_exp;
}
};
int main()
{
using namespace std;
Work e1("Kiran",600160,"Implementation Specialist", strlen("Kiran"),strlen("Implementation Specialist"),24,5);
cout << "Name: " << e1.GetName() << endl;
cout << "Code: " << e1.GetCode() << endl;
cout << "Designation: " << e1.GetDes() << endl;
cout << "Age: " << e1.GetAge() << endl;
cout << "Experience: " << e1.GetExp() << endl;
}
Also, I get the error no-match for operator<<. I am not printing any class . I am just calling the function of the derived class here.
Employee::GetCodedoesn't call anything.Employee::GetCode()does.e1.GetName()doesn't return any value (the return type ofWork::GetNameisvoid), so it's not clear what it is you are trying to print.