i am a new learner to c++ so i am learning dynamic binding and i did a small program
#include<iostream>
using namespace std;
class Employee;
class Employee
{
public:
int age,len;
char *name;
int salary;
};
int set(Employee &s)
{
cout<<"Enter the name\n";
cin>>s.name;
cout<<"Enter the age \n";
cin>>s.age;
cout<<"Enter the Salary\n";
cin>>s.salary;
return 0;
}
int display(Employee &s)
{
cout<<s.name<<s.age<<s.salary;
return 0;
}
int main()
{
Employee ob1;
int (*f)();
int c;
cin>>c;
if(c==1)
{
f=set(ob1);
}
else
f=display(ob1);
You make a lot of mistakes with pointers, so it would be best for you to avoid them.
In your Employee class, use a std::string for name and remove the "len" attribute.
In your main(), f is declared as a function pointer but never used as such. You should remove it completely.