How to make it work? Error/comment line before return 0;
#include <iostream>
#include <vector>
#include <memory>
using namespace std;
class Base
{
public:
void foobar() { cout << "foobar"; }
};
class Derived : public Base
{
public:
void print() { cout << "hello world!"; }
};
int main(int argc, char *argv[])
{
vector<unique_ptr<Base>> bases;
bases.push_back(unique_ptr<Base> (new Derived()));
//ok
bases[0]->foobar();
//error
//how can I make this works?
static_cast<Derived*> (bases[0])->print();
return 0;
}