J
July
Hello!
consider the following code:
class A {
public:
virtual void f() const{
cout << "A::f()" << endl;
}
};
class B : public A {
public:
void f() {
cout << "B::f()" << endl;
}
};
int main()
{
B b;
A *pa = &b;
pa->f();
}
the output is A::f()
neither b nor pa is const , why A::f() get called?
Will somebody explain this?
Thanks
consider the following code:
class A {
public:
virtual void f() const{
cout << "A::f()" << endl;
}
};
class B : public A {
public:
void f() {
cout << "B::f()" << endl;
}
};
int main()
{
B b;
A *pa = &b;
pa->f();
}
the output is A::f()
neither b nor pa is const , why A::f() get called?
Will somebody explain this?
Thanks