References in C++ are a conveneint construct that allow us to simplify the following C code:
f(object *p){
//do something
}
int main(){
object* p = (object*) calloc(sizeof(object));
f(p);
}
to
f(object& o){
//do something
}
int main(){
object o = object();
f(o);
}
Shared pointers are another convenience in C++ that simplify memory management. However, I am not sure how to pass a shared_ptr
to a function like f(object& o)
which accepts arguments by reference?
f(object& o){
//do something
}
int main(){
shared_ptr<object> p (new object());
f(*p);
}
Will the shared pointer be incremented when its object is passed by reference to a function?