如何在 C++ 中将指针转换/转换为引用
如何将指针 (Object *ob
) 传递给原型为 void foo(Object &)
的函数?
How can I pass a pointer (Object *ob
) to a function which prototype is void foo(Object &)
?
推荐答案
这样称呼:
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.
相关文章