#include <iostream>
#include <map>
#include <memory>

using namespace std;

struct foo {
  virtual void print() { cout << "foo";  }
};

struct bar : foo {
  virtual void print() { cout << "bar"; }
};

int main()
{
  map<int, shared_ptr<foo>> test = { {1, shared_ptr<foo>(new foo)}, {2, shared_ptr<foo>(new bar)} };
  test[2]->print();
}