UrbanPro

Learn C Language from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

How would you explain C++'s rule of 0, rule of 3, and rule of 5 in your own words?

Asked by Last Modified  

Follow 5
Answer

Please enter your answer

Electrical Engineer from IIT Kanpur ,By profession Software Engineer and Teacher by passion

These rules are instrumental when you design your class. When you create/write a new class, you always think of 5 place holder methods in it. Earlier it was three, but after C++ 11 it became 5. They are: Constructor Copy Constructor Assignment operator; After C++11 - Move Copy constructor Move Assignment...
read more

These rules are instrumental when you design your class.

When you create/write a new class, you always think of 5 place holder methods in it.

Earlier it was three, but after C++ 11 it became 5.

They are: 

  1. Constructor 
  2. Copy Constructor
  3. Assignment operator; After C++11 - 
  4. Move Copy constructor 
  5. Move Assignment operator.
  • Rule of 0 means, your class is designed in a way, such that you don't need any of 1,2,3,4,5
  • Rule of 3 means, you need 1,2,3
  • Rule 3 of 5 means, you need all 1,2,3,4,5

Best case is to design a class so that you have a rule of 0. But it's not always possible.

It will depend on the nature of your class members. It's bad practice to have them as raw pointers because then you have to write these constructors carefully and also think about resource leakage. Sometimes, we make them shared pointer or unique pointer etc. to reduce our work of writing these constructors and methods. If your class members are themselves following the rule of 0,3,5 etc., then it will also affect your decision whether you have to give all 5 or 0 or 3.

In a nutshell, it's always a good practice to think about these five methods, whenever you write a new class. 

Good question!!

read less
Comments

Related Questions

What are security issues in the C language?
Even though the C language is widely used in different systems still it has many security flaws associated with it. This article focuses on discussing security vulnerabilities in the C language. Mainly...
Avinesh
0 0
7
How can I avoid the error messages?
When there is a syntax error in the program the compiler indicates it by giving error messages. By following proper syntax we can avoid error messages. Syntax is like grammar rules of english language.
Yusufali
Is C programming necessary to learn to become a software engineer?
C language is starting language for programming, if you will understand the concept of C language then it would be very easy to learn all programming language because somehow concepts are similar
Ujwalajagdale
0 0
7

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

C Program Sample Application
//Standard Library Functions(Header Files used) #include<stdio.h> #include <conio.h> //Main method int main() { // function for clearing screen clrscr(); // function to print the output...

Necessity of Theory and Practical in Computer Science.
Upon studying a subject both theory and practical are important. Usually many schools concentrate more on theory and the marks not on the practical. Other and opposite kind of people prefer practical...

Introduction to Programming Languages
What is a Programming Language? A programming language is a formal computer language or constructed language designed to communicate instructions to a machine, particularly a computer. Programming languages...

Structures in C
A structure is a collection of one or more data members possibly of different data types, grouped together under a single name for convenient handling. Defining a Structure: In general terms,...

Program to swap the value of two variables without using third variable(simplest way)...
int main() { int a=10,b=20; printf("values of a before swap ="%d,a); printf("values of b before swap ="%d,b); a=a+b; b=a-b; a=a-b; printf("******************"); printf("values of a after swap...

Recommended Articles

Lasya Infotech is a Hyderabad based IT training institute founded in 2016 by O Venkat. Believing in his innovation, passion and persistence and with a diverse blend of experience, he started his brainchild to deliver exemplary professional courses to aspiring candidates by honing their skills. Ever since the institute envisions...

Read full article >

Brilliant Academy is one of the reputed institutes for B.Tech tuition classes. This institute is specialised in delivering quality tuition classes for B.E, Engineering - all streams and Engineering diploma courses. Incorporated in 2012, Brillant Academy is a brainchild of Mr Jagadeesh. The main motto of the academy is to...

Read full article >

Applications engineering is a hot trend in the current IT market.  An applications engineer is responsible for designing and application of technology products relating to various aspects of computing. To accomplish this, he/she has to work collaboratively with the company’s manufacturing, marketing, sales, and customer...

Read full article >

Software Development has been one of the most popular career trends since years. The reason behind this is the fact that software are being used almost everywhere today.  In all of our lives, from the morning’s alarm clock to the coffee maker, car, mobile phone, computer, ATM and in almost everything we use in our daily...

Read full article >

Looking for C Language Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for C Language Classes?

The best tutors for C Language Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn C Language with the Best Tutors

The best Tutors for C Language Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more