I have a class named House that extends from a class named City.
class City
{
public:
string get(){
return "San Francisco"
}
};
class House : public City
{
public:
string get(){
return "My House"
}
};
int main()
{
City world[2];
House h;
world[0] = h;
cout << world[0].get() << endl;
}
The result I want back is "My House", but instead I get "San Francisco". Why is this and how do I fix it? I thought that if you named a function the same as a function existing in the inherited class, then that function would always be called.