So I am aware of the Rule of 5, and of the rule that if one deletes or defaults any one of the 5, they should do the same for all 5. (Herb Sutter) But not delete the dtor !
I am trying to establish when I need to write my own copy constructors etc.
I was wondering if there were any other considerations to make, apart from the following list (
This is the main question)?
1 There is a member pointer that owns something
2 There is dynamically allocated members
3 Whenever an implicit copy ctor et al. is deleted, or not defaulted, or not defined, or not trivial?
With 2, if the member is an STL container, there is no need to worry because the object is on the stack, but it's data is on the heap?
With 3, I am a little confused by the documentation on cppreference:
Implicitly-defined copy constructor
If the implicitly-declared copy constructor is neither deleted nor trivial, it is defined (that is, a function body is generated and compiled) by the compiler if odr-used.
|
I understand the the "is neither deleted" part, but not the "nor trivial". I was expecting "Not deleted and trivial". It has the same text for the move constructors as well.
I spent ages looking in the C++14 draft standard to find where that came from, the best I could get was:
Section 12.8 note 13
A copy/move constructor that is defaulted and not defined as deleted is implicitly defined if it is odr-
used (3.2) or when it is explicitly defaulted after its first declaration.
|
I couldn't see where the standard mentioned the need for it not being trivial, or have anything to do with being trivial. I am guessing it should do though, given the definition of trivial.
Anyway I am a novice at reading the standard, I don't have a lawyer's hat that any where near fits, vastly less a barrister's one :+)