I came across people passing data objects as:
declaration:
DataObject * data = 0;
calling it as:
SomeMethod( data );
definition of Somethod:
void SomeMethod(SomeObject * & object)
My obvious question is, when and why do you have to do this (& *)? Is it passing the pointer as reference?
Is it passing the pointer as reference?
Yes, that's exactly what it is doing.
This is useful if you want to modify the pointer itself, rather than the data it is pointing to. Remember that C++ passes by value, so if you pass SomeObject*
, you are passing a copy of the pointer to SomeObject
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With