This question already has an answer here:
Earlier today I asked a question that led to another one: When should I use =delete
? I don't think there is a post dedicated solely to =delete
on SO, so I looked it up in a book called "The C++ Programming Language". I will list my findings in my answer below.
Please comment or answer if there's more to say or if I'm mistaken.
It turns out that
=delete
is extremely useful! Here are a few examples:Basically we can prevent copying base classes because it might often lead to slicing:
It's also useful when a template function cannot run with a certain type:
=delete
can also disallow undesired conversions:Some more advanced uses of
=delete
include prohibiting stack or free store allocation:... You get the idea. Hope this helps someone!
=delete
can help write readable, bugless and elegant code.Edit:
As it was correctly pointed out in the comments, it is now impossible to delete
FS_Only
objects, so this one isn't such a good use of=delete
after all.