- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is The Rule of Three with reference to C++?
The Rule of three is a rule of thumb when using C++. This is kind of a good practice rule that says that If your class needs any of
- a copy constructor,
- an assignment operator,
- or a destructor,
defined explicitly, then it is likely to need all three of them.
Why is this? Its because, if your class requires any of the above, it is managing dynamically allocated resources and would likely be needing the other to successfully achieve that. For example, if you require an assignment operator, you would be creating copies of objects currently being copied by reference, hence allocating resources. You'll need the copy constructor for copying and destructor for freeing up these resources.
- Related Articles
- C++ Rule Of Three.
- Rule of Three vs Rule of Five in C++?
- Rule Of Three in C++
- What is Rule of Five in C++11?
- What is the locality of reference?
- What is the frame of reference?
- What is the divisibility rule of 11?
- What is the working of Association Rule?
- What is a reference variable in C++?
- What is RHS rule?
- What is pass by reference in C language?
- What is call by reference in C language?
- What is the OSI Reference Model?
- What is ASA congruence rule ?
- What is Association rule learning?

Advertisements