I'am trying to print class A user define funtion via class B. Class A and class B are inherited but still I cannot print "name" and "ID" of a person in main through class B funtion. When I call show() funtion in main Directly it prints Name and ID enterted but when I call class B funtion Name and ID are totally blank.
#include<iostream>
#include<string>
using namespace std;
class A
{
protected:
string name;
string ID;
public:
void set()
{
cout << "Enter your name: ";
cin >> name;
cout << "Enter Your ID: ";
cin >> ID;
}
void show()
{
cout << "Name: " <<name << endl;
cout << "ID : " << ID << endl;
}
};
class B: public A
{
public:
void Bshow()
{
cout << "THe name of person and ID of a person is: " << endl;
A::show();
}
};
void main()
{
A a;
B b;
a.set();
cout << endl;
b.Bshow();
cout << endl;
system("pause");
}