#include <iostream>
#include <string>
using namespace std;
class parent
{
int x=0;
public:
int getx()
{
return x;
}
};
class child : public parent
{
int x=7;
};
int main()
{
parent cat;
cout << cat.getx();
child s;
cout << s.getx(); //stops working here
return 0;
}
Here is an example of the issue I am having. Why doesn't it print 7 when i call cout << getx() as a derived object?