Document Why C++ Special Member Functions Are Deleted [DI24] [WHY]

Document Why C++ Special Member Functions Are Deleted [DI24] [WHY]

Tip DI24

C++ allows special member functions to be deleted, which can prevent the compiler from trying to auto-generate them. Deleting such functions is typically useful in cases where they might cause bugs.

When deleting such functions, explain why they’re actually deleted. It’s important for future programmers to know if they’re deleted because they’re not needed/tested yet or if they’re known to cause problems.

For example, the below isn’t really helpful:

// Deleted to disallow copying. MyBuffer(const MyBuffer&) = delete;

But the following provides key information on why copying is prevented:

// Deleted since the buffer contains dynamically-allocated memory // that would be expensive to copy, and copying isn't needed yet. MyBuffer(const MyBuffer&) = delete;
Say goodbye to blindsided code updates ad.png