shawtynerd
shawtynerd

Reputation: 23

Creating a reference to dereferenced pointer?

I recently looked at some code, and someone used this:

void Foo(vector<vector<int>>* arr_ptr){
vector<vector<int>>& arr = *arr_ptr;
//use arr
}

Is there a purpose to create a reference to a dereferenced pointer? As long as the pointer isn't null, couldn't the same result be performed using just this:

void Foo(vector<vector<int>>& arr) {
//use arr
}

Upvotes: 0

Views: 177

Answers (1)

Scott Hunter
Scott Hunter

Reputation: 49920

It wouldn't be the the same to the code calling this method.

In the original code, the argument would be a pointer to type X; in your version, it would be of type X.

Upvotes: 4

Related Questions