I can't seem to understand how the compiler priorities to which function to go. here is an example code:
#include <iostream>
using namespace std;
class A{
public:
int f() {return 1;}
virtual int g() {return 2;}
};
class B: public A {
public:
int f() {return 3;}
virtual int g() {return 4;}
};
class C: public A{
public:
virtual int g() {return 5;}
};
int main () {
A *pa;
B b;
C c;
pa = &b;
cout<< pa -> f()<<endl<<pa -> g() << endl;
pa = &c;
cout<< pa -> f() << endl; cout<< pa -> g() << endl;
return 0;
}
to which function (g() and f()) will be called each time and why?