I have two class.
class A:
class B: public A
{
//new function
void setHint(...);
}
And have struct data.
typedef std::shared_ptr<A> window_ptr;
std::stack<window_ptr> m_windowsStack;
m_windowsStack.push(std::make_shared<A>("Hint"));
m_windowsStack.push(std::make_shared<B>("Game"));
And have function find in stack:
std::shared_ptr<A> WindowManager::findWindow(std::string title)
{
... return result;
}
And use function for find element in stack:
auto w = findWindow("Game"); //return element type B
w->setHint(window);
But it turns out that function findWindow return type A
. I get error "'class A' has no member named 'setHint'
w->setHint(window);"
Do I need to declare setHint function in class A as virtual function? How do I make a variable to automatically understand that it is of type B?