How can you protect a class object from being copied? Explain the difference between deleting the copy constructor and making it private.
Last updated
Modern way: mark the copy constructor and copy assignment
= delete. Any copy, even from members or friends, is a clear compile-time error.Old C++98 idiom: declare them
privatewithout a definition. Members and friends can still call them, so the error appears only at link time with worse diagnostics.Declaring copy operations suppresses implicit move generation, so define moves explicitly if the class should remain movable.