R
Rahul
Hi Everyone,
I have the following code,
class AA
{
public:
int i;
};
class B : public AA
{
public : int i;
};
int main()
{
B obj;
obj.AA::i = 10;
obj.B::i = 20;
cout<<obj.AA::i<< " " <<obj.B::i<<endl;
obj.i =
10; //
Isn't this ambiguous?
cout<<obj.AA::i<< " " <<obj.B::i<<endl;
return(0);
}
I expected a compilation error when obj.i is used as there are two
versions if i available in class B. How does the compiler manage to
resolve the reference to the correct i?
Thanks in advance ! ! !
I have the following code,
class AA
{
public:
int i;
};
class B : public AA
{
public : int i;
};
int main()
{
B obj;
obj.AA::i = 10;
obj.B::i = 20;
cout<<obj.AA::i<< " " <<obj.B::i<<endl;
obj.i =
10; //
Isn't this ambiguous?
cout<<obj.AA::i<< " " <<obj.B::i<<endl;
return(0);
}
I expected a compilation error when obj.i is used as there are two
versions if i available in class B. How does the compiler manage to
resolve the reference to the correct i?
Thanks in advance ! ! !