Quest
Quest

Reputation: 2843

Disable operator= and copy constructor

Is there a way to disable operator= and copy constructor and allow using std::move() only? I know that i can do

foo& operator= (const foo&) = delete;
foo(const foo&) = delete;

but this will disable std::move too.

What i want is to block copying of this class and allow only foo foo2 = std::move(foo1);

Btw. I have private contructor.

Upvotes: 0

Views: 332

Answers (1)

juanchopanza
juanchopanza

Reputation: 227468

Use defaulted special member functions:

foo(foo&&) = default;
foo& operator=(foo&&) = default;

Upvotes: 6

Related Questions