如何在 C++ 中将指针转换/转换为引用 [英] How to cast/convert pointer to reference in C++

查看:47
本文介绍了如何在 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.

这篇关于如何在 C++ 中将指针转换/转换为引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆