So, as we’re all hopefully aware, in Object-oriented programming when the occasion comes when you need somehow access an instance of a class in another class’s method, you turn to passing that instance through arguments.
I’m curious, what’s the difference in terms of good practice / less prone to breaking things when it comes to either passing an Object, or a Pointer to that object?
Get into the habit of passing objects by reference.
If you need to modify the original object, omit the
constqualifier.If you want to be able to accept an empty/nothing answer, pass it by pointer.
If you want to do stuff to a local copy, pass it by value.
Problems will only really pop up when you introduce tons of concurrency. By that time, you will know enough to know when to not use certain passing techniques.