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 is the best website to learn c language?
First go through the book "Let Us C" by Yashawant Kanetkar, then try to implement few small codes by your own, it takes time but you will learn it properly by experience only
Nom
Can a file other than a .h file be included with #include?
Yes. user defined header file ex:#include "nim.c"
Pankaj
0 0
7
In how many days can we learn the C language?
Around one month and depends upon you how much time you give.
Ravi Shankar
0 0
9
How do I program a game using C program?
Programming a game in C involves several steps. Here's a simplified guide to get you started: Define Your Game Concept: Clearly outline the game's concept, rules, and objectives. Setup Your Development...
Sumitha
0 0
6
What is a macro, and how do you use it?
A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro. There are two kinds of macros. They differ mostly in what they look...
Sandeep

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

Ask a Question

Related Lessons

Memory Layout of C Programs
A typical memory representation of C program consists of following sections. Text Segment: A text segment, also known as a code segment or simply as text, is one of the sections of a program in an object...

Lets know about far, near and huge pointers for fresher interview purpose
All of these three candidates relate to 16 bit architecture where segmented memory architecture was there. They are not at all relevant for present days 32 or 64 bit architecture where the way of memory...

Programming Practice Technique
Any Programming Language required an Algorithm. Algorithm - It is the finite set of instructions in which each and every instruction has the meaning, instructions are not ambiguous and all the instructions...

Why Indexing Should Start From Zero In Array ?
Why numbering should start at zero? To denote the subsequence of natural numbers 2, 3, ..., 12 without the pernicious three dots, fourconventions are open to usa) 2 ≤ i < 13b) 1 < i ≤ 12c)...

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

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