I have the following piece of C++ code:
#include <iostream>
using namespace std;
class X{
    public:
        int i;
};
class Y: public X{
    public:
        int i;
};
int main()
{
    X ob1;
    X ob2;
    Y ob3;
    ob1.i = 1;
    ob3.X::i=2;
    ob3.i=3;
    ob2=ob3;
    cout << ob2.i;
}
I expect it prints 3 (while it does 2) because ob2.i seems to me to be equivalent to ob3.i which was set to 3 but it seems that the compiler assumes this as the inherited i from the class X. Why?
 
    