I'm creating a program and I need the class 'Child' in the following code to inherit the value of 'age' from the class 'Mother'.
#include <iostream>
using namespace std;
class Mother {
public:
int TellAge(void);
protected:
int age;
} MObj;
class Child:protected Mother {
public:
void ChildTellAge(void);
} CObj;
int Mother::TellAge(){return MObj.age=34;}
void Child::ChildTellAge(){cout << "My mommy is " << CObj.age;}
int main()
{
MObj.TellAge();
CObj.ChildTellAge();
cin.get();
}
But for some reason, the child doesn't inherit the value of 'age', and instead it just prints "0" (and in the case of a string, nothing). Any help would greatly be appreciated!