Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [rule-of-three]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
10 votes
4 answers

If you follow the rule of Zero, how will you debug the construction of an object?

Everyone is quick to point out the "Rule of Zero" in code reviews, peer conversations, and Stack Overflow comments/answers. I am not a believer. I'd like to be. Usually if enough people agree on ...
Christopher Pisz's user avatar
5 votes
2 answers

Is the rule of 5 a valid extension of the rule of 3, or does it imply premature optimization?

I'm familiar with the notion in c++ of the rule of 3, however since the release of C++11 I've seen some sources suggesting it should be extended to a "rule of 5", I.e. the move constructor and move ...
Jules's user avatar
  • 17.8k
18 votes
1 answer

Reasoning to wait until third time in the Rule of Three?

I just came across the article "Rule of Three" in wikipedia Rule of three is a code refactoring rule of thumb to decide when a replicated piece of code should be replaced by a new procedure. It ...
Louis Rhys's user avatar
  • 6,132
7 votes
3 answers

How to setup the c++ rule of three in a virtual base class

I am trying to create a pure virtual base class (or simulated pure virtual) my goal: User can't create instances of BaseClass. Derived classes have to implement default constructor, copy constructor,...
Minion91's user avatar
  • 173
20 votes
6 answers

The rule of 5 - to use it or not?

The rule of 3 (the rule of 5 in the new c++ standard) states : If you need to explicitly declare either the destructor, copy constructor or copy assignment operator yourself, you probably need to ...
BЈовић's user avatar