I have the following set up:

```
class Base {
private:
// data members
public:
// methods
// pure virtual methods
virtual Base* clone() const =0;
}

class Derived : public Base{
private:
// more data members
public:
// more methods
// pure virtual methods overridden
Derived* clone() const override{
return new Derived(*this);
}

```

I now want to introduce a new derived class which, in the context of a decorator pattern, has a unique pointer to a Base class object as a data member. My question is then how to properly implement the clone() method because the "standard" implementation leads to a compile time error as the unique pointer can't be copied:

```
class DecoratedDerived : public Base{
private:
unique_ptr<Base> ptr;
// more data members
public:
// more methods
// pure virtual methods overridden
DecoratedDerived* clone() const override{
return new DecoratedDerived(*this); // compiler error
}

```

One solution would be to just construct a new DecoratedDerived class object in the clone method (by explicitly deep copying all the members associated to the current object) and then passing a pointer to this. However this is quite time consuming if the class has a lot of other members.

I should also say that I am only using a unique pointer because this seems the standard smart pointer to use in modern C++. In particular before I used C+11 I had just designed my own smart pointer which took care of all the memory management etc. so that for that type of smart pointer there would be no issue with the clone method in the decorated class.

Thanks in advance for your help!