This was just something I came across while relearning C++. C++11 has added move semantics so these guidelines have probably changed since then, but nevertheless, I found the read quite enlightening.
When I learned c++, I would use constructors and destructors, but never really cared about a copy constructor or an assignment operator. Meh, it worked for me, but I appreciate the principle today.
More important since C++11, I think, is the Rule of Zero: "Classes that have custom destructors, copy/move constructors or copy/move assignment operators should deal exclusively with ownership. Other classes should not have custom destructors, copy/move constructors or copy/move assignment operators."
4 comments
1 u/hopo [OP] 07 Jul 2015 09:35
This was just something I came across while relearning C++. C++11 has added move semantics so these guidelines have probably changed since then, but nevertheless, I found the read quite enlightening.
1 u/Shammah 07 Jul 2015 09:45
If I recall correctly it's now the rule of five ;D
1 u/bufferoverflow 07 Jul 2015 13:56
When I learned c++, I would use constructors and destructors, but never really cared about a copy constructor or an assignment operator. Meh, it worked for me, but I appreciate the principle today.
1 u/iguessillmakeanacct 07 Jul 2015 17:05
More important since C++11, I think, is the Rule of Zero: "Classes that have custom destructors, copy/move constructors or copy/move assignment operators should deal exclusively with ownership. Other classes should not have custom destructors, copy/move constructors or copy/move assignment operators."