I am trying to return a unique_ptr
from
a vector of base class pointers to apply polymorphism
as unique_ptr
can not be copied.
Is there any way around this?
See he
function.
#include <bits/stdc++.h>
using namespace std;
class shape {
public:
virtual void foo() = 0;
};
class circle : public shape {
public:
virtual void foo() override {cout << "I am circle" << endl;}
};
class square : public shape {
public:
virtual void foo() override {cout << "I am square" << endl;}
};
unique_ptr<shape> da(int x) {
if(x)
return make_unique<circle>();
return make_unique<square>();
}
unique_ptr<shape> he(const vector<unique_ptr<shape>> &t, int x) {
return t[x];
}