I am attempting to create an abstract method for cloning classes derived from base and returning them as a shared_ptr like so:
class Base {
public:
virtual std::shared_ptr<BaseSymbol> clone() = 0;
};
class Derived : public Base {
public:
Derived(const Derived& derived);
std::shared_ptr<Derived> clone();
};
This is getting me a compilation error. I know this is possible to achieve this with normal pointers, so how can I get this to work with shared pointers?
covariance is only possible with pointer/reference.
For smart pointer, you have to "duplicate" the interface:
CRTP might help to avoid to rewrite the same pattern.