Say, I have the following class "Object" and I want to create clone of it.
1 2 3 4 5 6 7 8 9 10 11 12
|
class Object
{
public:
int Id;
string Name;
auto getClone()
{
unique_ptr<Object> clone { new Object { Id, Name } };
//auto clone = make_unique<Object>();
return clone;
}
};
|
The code perfectly works. But how to do the same with std::make_unique?
1 2 3 4 5 6
|
auto getClone()
{
// Does not work!
auto clone = make_unique<Object>(new Object { Id, Name });
return clone;
}
|
Last edited on
@keskiverto
Thanks! Your code works but with one condition - there must be a constructor which receives Id and Name. With it, all works fine! :)