I would like to know the difference between defining a function to take an argument to a reference of an object (case 1) and defining a function to take an argument to a pointer of an object (case 2).
Of course the way that you refer to the object itself differs, therefore I am asking about the different capabilities that one has by using the one or the other way when defining a function, as well as the context that the one or the other way of defining a function is used.
1) Reference to the object in the function's arguments
void function(T& t) {
// Procedure that might change
// the value of the object t.
// t is the object
}
void main() {
T object;
function(object);
}
2) Pointer to the object in the function's arguments
void function(T* t) {
// procedure that might change
// the value of the object *t
// *t is the object
}
void main() {
T object;
function(&object);
}
Note: there are some questions that discuss the difference between a pointer variable and a pointer variable, but this one examines the context of using the as function arguments.