When using std::map in c++, is it possible to store inherited classes as their "base class" in the map and still being able to call their overloaded methods? See this example:
#include <iostream>
#include <map>
class Base
{
public:
virtual void Foo() { std::cout << "1"; }
};
class Child : public Base
{
public:
void Foo() { std::cout << "2"; }
};
int main (int argc, char * const argv[])
{
std::map<std:string, Base> Storage;
Storage["rawr"]=Child();
Storage["rawr"].Foo();
return 0;
}
This following code writes "1". Which somehow tells me that polymorphism doesn't work when you use std::map.