# C++ Rule of zero **[Rule of zero](https://en.cppreference.com/w/cpp/language/rule_of_zero)** states that if a class manages resources correctly via [[raii|RAII]], it should define no special member functions at all—not destructor, copy constructor, copy assignment, move constructor, or move assignment. The compiler's defaults work correctly when members are themselves RAII-compliant (e.g., `unique_ptr`, `vector`, `string`). Prefer the rule of zero by using standard library containers and smart pointers instead of manual resource management. ## Example This example shows how using standard library types makes manual special members unnecessary. ```cpp // compile: g++ -o rule_zero rule_zero.cpp // run: ./rule_zero // description: rule of zero: no special members needed with standard containers #include #include #include class Container { private: std::vector data; std::unique_ptr buffer; public: Container(size_t n) : buffer(std::make_unique(n)) {} // No destructor, copy constructor, copy assignment, move constructor, or move assignment needed // Compiler-generated versions work correctly due to RAII members }; int main() { Container c1(100); Container c2 = std::move(c1); // move works correctly Container c3 = c2; // copy works correctly return 0; } ```