How can you protect a class object from being copied? Explain the difference between deleting the copy constructor and making it private.

Last updated 21 June 2026

  • 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 private without 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.

  • https://www.geeksforgeeks.org/cpp/prevent-object-copying-using-deleted-functions-in-cpp/
  • https://www.geeksforgeeks.org/cpp/how-to-implement-copy-constructor-for-deep-copying-in-cpp/
  • https://www.geeksforgeeks.org/cpp/how-to-declare-a-copy-constructor-in-a-derived-class-in-cpp/
All C++ interview questions