Tuesday, 15 May 2018

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



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


Answer



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.


No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...