Proper Class Design Part 3 - Operators, the Rule of Zero and the Rule of Three

Channel:
Subscribers:
2,640
Published on ● Video Link: https://www.youtube.com/watch?v=MRArxhYt6Dg



Duration: 1:09:11
265 views
2


Overloaded Operators allow your classes to be used with things like +, -, /, [], and so forth. We typically use them with mathematical classes to have them act math-y, or we overload [] for array-like classes to make them array-y.

The Rule of Zero (which I usually follow) states that if you don't have any memory allocations or deallocations in your class, then you don't need a destructor, copy constructor, or assignment operator.

The Rule of Three (now the rule of Five, but w/e) states that if you do a allocation (such as new) in your constructor, you will need a destructor, a copy constructor, and an assignment (operator=) operator.







Tags:
csci 41
rule of zero
c++
rule of three
proper class design
oop
operators
operator overloading