Questions tagged [rule-of-five]

20 questions
0
votes
1 answer

What is the relationship between the Rule of Five, Inheritence, and Polymorphism in C++?

I have been learning about destructors, copy constructors, move constructors, and the rest. I also learned the recommendation about marking your destructor as virtual in a base class that has derived classes inheriting from it. According to the Rule…
3DMage
  • 13
  • 2
0
votes
1 answer

Can assignment operations which declared as default have reference qualifiers?

When declaring assignment operations as default, is there anything wrong to make them reference qualified to prevent assignment to temporaries? (Most often than not, it prevents stupid errors). Common resources, do not say anything about reference…
0
votes
1 answer

Is this a proper implementation of the Rule of Five (or Rule of Four and 1/2)?

I am studying the Rule of Five and it's cousins (Rule of Four and 1/2, Copy and Swap idiom, Friend Swap Function). I implemented the Rule of Four and 1/2 on a test class. It compiles well. Is there any hidden mistake in my implementation? I am…
Rsevero
  • 157
  • 2
  • 11
0
votes
0 answers

Implement C++ assignment operator in terms of constructor

Background Suppose you want to implement a resource-managing class in C++. You cannot use the Rule of Zero or Rule of Five Defaults, so you actually need to implement copy and move constructor, copy and move assignment operator, and destructor. In…
Daniel H
  • 7,223
  • 2
  • 26
  • 41
0
votes
1 answer

Rule-of-five for a BST class in C++

I am implementing a binary search tree class and was wondering if my move/copy constructors and assignment operators are implemented correctly. (It seems to work correctly, but this is my first time implementing these constructors and assignment…
1
2