Reason to Pass a Pointer by Reference in C++?

Matthew Hoggan picture Matthew Hoggan · Apr 20, 2012 · Viewed 101.7k times · Source

Under which circumstances would you want to use code of this nature in c++?

void foo(type *&in) {...}

void fii() {
  type *choochoo;
  ...
  foo(choochoo);
}

Answer

David Z. picture David Z. · Apr 20, 2012

You would want to pass a pointer by reference if you have a need to modify the pointer rather than the object that the pointer is pointing to.

This is similar to why double pointers are used; using a reference to a pointer is slightly safer than using pointers.