What is the exact difference between having myMethod(Thing& a) or myMethod(Thing a)? Because later you still ned to use &a if you want the address of the object.. I’m not sure when to use what..
What is the exact difference between having myMethod(Thing& a) or myMethod(Thing a)? Because later
Share
Three differences:
ayou change the original and vice versa.Thing ayou invoke the copy constructor. If the copy constructor has to do a lot of things, that could affect how fast the code runs.Thing abut you can always doThing &a.Finally, if you don’t intend for the caller to be able to change the underlying object, you should probably pass by const reference (
const Thing &a)