Interview Question

Rule of 3/5/0?

Prefer the rule of zero; define ownership special members only when necessary.

💡 Concept ✅ Quick Revision 🧠 C++

Answer

The rule of three, five, and zero is guidance for managing special member functions and ownership. • If a type manually defines a destructor, copy constructor, or copy assignment, it often needs all three. • With move operations, an owning type may need five special members. • The rule of zero prefers members such as containers and smart pointers so no custom ownership members are needed.

💡 C++ Example

class Report { std::string title_; std::vector<int> values_; public: Report() = default; };

⚡ Quick Revision

Prefer the rule of zero; define ownership special members only when necessary.