How to cast/convert pointer to reference in C++

Dewsworld picture Dewsworld · Apr 16, 2012 · Viewed 129.4k times · Source

How can I pass a pointer (Object *ob) to a function which prototype is void foo(Object &) ?

Answer

David Heffernan picture David Heffernan · Apr 16, 2012

Call it like this:

foo(*ob);

Note that there is no casting going on here, as suggested in your question title. All we have done is de-referenced the pointer to the object which we then pass to the function.