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

Can you suggest me some books for learning C?
"letus c" for c programming yashwant kanetkar
Yamun
what is the significance of lvalue?
An lvalue (locator value) represents an object that occupies some identifiable location in memory (i.e. has an address).
Abhishek
Why do we use # in C programming?
In the C programming language, # is used for preprocessor directives. The preprocessor is a program that runs before the compiler and processes special directives that begin with # . These directives allow...
Dhanya
0 0
5
What is the actual size of INT in the C language, 2 or 4 bytes?
The actual size to int is determined by the compiler as the program runs. But theoretically the size is 2 bytes. You can increase the size by adding keyword long infront of it to make the size 4 bytes. Eg int a; // 2 bytes Long int b; // 4 bytes
Kunal

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 to print Block Letter and Small Case Alphabets using C
/* WAP to print Block Letter and Small Case Alpahbets using C*/ //Hint:use ascii code(value) to print #include#include void main(){ int i; clrscr(); //Block Letters Alphabets printf("Block Letters Alphabets\n");...

C Program-Vowels and Consonants
/*WAP to print the character entered by user is a vowel or consonant*/ //Header files #include<stdio.h>#include<conio.h> //Main functionvoid main(){ char c; //Function for clearing screen...

Recursion in C Programming
The process of calling a function by itself is called recursion and the function which calls itself is called recursive function. Syntax of Recursive Function returntype recursive_func () { statements; ...
R

Ravindra Yadav

2 0
0

Difference Between C Language and C Program
C Language: C Language is structured, high level and machine independent language. C Program: C Program is the collection of functions that are supported by C library.
S

Shashwat Kumar

0 0
0

Tips of learning Java Language/Other Programming Languages
1.You should know the basic concept: If we talk about programming languages so basic concept are same in all the high level languages. So you should know the basic concept firstly then you can easily understand...
I

ICreative Solution

0 0
0

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