When asked to attempt to release object I came up with the attached solution and it seems to work perfectly, I am curious if this is valid or if there could be some errors i am ignorant to here?
This is the instructors answer here
When asked to attempt to release object I came up with the attached solution and it seems to work perfectly, I am curious if this is valid or if there could be some errors i am ignorant to here?
This is the instructors answer here
If you GetPhysicsHandle returns nullptr
then you would dereference a null pointer which is bad. The check for GrabbedComponent is unneeded as ReleaseComponent already does that.
A couple comments on your code.
NULL
, use nullptr
as that underline is most likely telling you. With that said pointers are convertible to bool, null pointers are false, anything else is true so you can just writeif (GetPhysicsHandle())
This reads lime natural English to me. “if I have a thing” instead of “if I don’t have a null pointer” which is something positive but worded negatively (i.e. null) can be a bit confusing at times.Thank you for the detailed reply, I appreciate your insights.