Returning a pointer vs. passing a reference to an object to store the answer in C++
问题 I have general question regarding the use of pointers vs. references in this particular scenario. Let's say that I have a function that is going to do some computation and store the value inside an object for later use by the caller. I can implement this by using either pointers or references. Although, I would prefer using references because I trying avoiding pointers as much as possible, are there any pros/cons of one approach over the other. The code using Pointers would be as follows: