Remove copy and move constructors from AxisDirection #3972
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Recently it took me a few hours and the help from @hernando to find out the reason of a failure in my code.
Let's say I am trying to make this function
Currently it is assigning some garbage to the direction because it is passed by copy, and not by reference. I was calling it with
AxisDirection::EAST
, that naïvely I supposed it was anenum
orenum class
.(the solution is passing the direction by reference... but the compiler was not helping me. The consequence was a crash later in the execution, not a compile error).
The implementation of the
create
function takes the pointer of the direction (pay attention to the&
in&directionIn
), that has a "wrong" value if it was copied. The consequence was a later segmentation fault when serializing to JSON.The easy solution I implement in this PR is deleting the copy and move constructors / assignments operator, so the compiler it not allowing me that wrong operation.
That opens the question: why is it taking a pointer? I find that obscure. But probably changing that implementation may break the API, and would be a lot of work.