Note to myself
Class Base{
public:
int a;
void seta(int x)
{
a = x;
}
};
Class Derived : public Base{
public:
Derived(){
a = 0;
}
int a;
};
main(){
Derived D;
D.seta(1);
cout << D.a << endl; --> this will print 0 only 'cos you just called the base class function which just sets its copy of variable 'a' which is masked by derived class varible having the same name.
}

0 Comments:
Post a Comment
<< Home