I get c2664 error when i try to create a unique pointer
i did write the copy constructor as well as assignment operator but still i keep getting the 2664 error
class UndoCopyPaste : public UndoRedo
{
private:
Container containerValue;
bool valid;
public:
UndoCopyPaste() = default;
UndoCopyPaste(Container* cont, std::string type);
UndoCopyPaste(Container trans, Container* cont, std::string type);
};
class UndoRedo
{
private:
std::string type;
protected:
Container* container;
public:
UndoRedo() = default;
UndoRedo(Container* cont, std::string undoType);
};
std::unique_ptr<UndoCopyPaste> undoCopyPastePointer = std::make_unique<UndoCopyPaste>(new UndoCopyPaste()); // error C2664: 'UndoCopyPaste::UndoCopyPaste(UndoCopyPaste &&)': cannot convert argument 1 from '_Ty' to 'const UndoCopyPaste &'
This code with make_unique:
x = std::make_unique<Foo>(a, b);
is essentially equivalent to this:
x = std::unique_ptr<Foo>(new Foo(a, b));
Note that the a, b pass to make_unique gets passed directly to the constructor of Foo. So your code
std::make_unique<UndoCopyPaste>(new UndoCopyPaste());
is equivalent to this:
std::unique_ptr<UndoCopyPaste>(new UndoCopyPaste(new UndoCopyPaste()));
You're actually passing new UndoCopyPaste() to the constructor of UndoCopyPaste! So just take out that parameter altogether:
std::make_unique<UndoCopyPaste>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With