c++ polymorphism and other function question
- by aharont
i have got this code:
class father{
public:
virtual void f() { cout<<1;}
};
class son:public father{
public:
void f() {cout<<2;}
};
void test (father x){x.f();}
int main(){
son s;
test(s);
}
the question says:
the output is '1', what is the rule about polymorphism that the programmer forgot and how can i fix it so the output would be '2'?
there is another rule that the programmer forgot when he wrote the father class, and he need to add an empty function to avoid problems from other sons of the father class. what is the rule and what is the missing function?
another question
write the g function so the next code would run with no crashes
int x=11; g(x)=22;